You are viewing limited content. For full access, please sign in.

Question

Question

copy file from network to repository based on path in sql

asked on April 17, 2020

I am trying to move pdf files stored in our network with their path and relevant project data stored in a sql database. I tried improvising a script that we had for migrating past projects. I am not getting any syntax errors but its not creating the documents in LF repository. Thanks in advance

This is what I have so far. 

namespace WorkflowActivity.Scripting.SDKScript
{
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Data.SqlClient;
  using System.Text;
  using Laserfiche.RepositoryAccess;
  using Laserfiche.DocumentServices;
  using System.IO;

  // Repository Access for 10.2

    public class Script1: RAScriptClass102
    {
        protected override void Execute()
        {
            //Create repository login
            Server myServ = new Server("LASERAPP");
            RepositoryRegistrationCollection repoRegColl = myServ.GetRepositories();
            RepositoryRegistration MyRepoReg = repoRegColl[GetTokenValue("RepositoryName").ToString()];
            Session mySess= new Session();
            mySess.LogIn("UserName", "Password", MyRepoReg);
            string folderpath = GetTokenValue("Repository Path").ToString();
            string repositoryname = GetTokenValue("RepositoryName").ToString();
            string VolumeName = GetTokenValue("VolumeName").ToString();
  string filePath =   GetTokenValue("File Path").ToString();

            if (filePath != ""){

            try{
                string FileName =  Path.GetFileName(filePath);
                string FileExt = Path.GetExtension(filePath);
                string ContentType = getContentType(FileExt); //Calling Method to get content type.
                SetTokenValue("TheFileExt",FileExt);
                SetTokenValue("TheFileName",FileName);
                SetTokenValue("TheContentType",ContentType);
                SetTokenValue("FolderPathInLF",folderpath);

                FolderInfo parentFolder = Folder.GetFolderInfo(folderpath, mySess);
            DocumentInfo document = new DocumentInfo(mySess);
                document.Create(parentFolder, FileName, VolumeName, EntryNameOption.AutoRename);
                document.RenameTo("Migrated Email - " + GetTokenValue("ForEachRow_Date").ToString());
                setTemplateFields(document); //Calling Method to set doc template and fields.
                DocumentImporter DI = new DocumentImporter();
                    DI.Document = document;
                    DI.ImportEdoc(ContentType,filePath);
                document.Dispose();
            }catch{};
//end if
    };
mySess.LogOut();
        } //end Method execute()

public void setTemplateFields (DocumentInfo Document){
            try{
                FieldValueCollection fvc = Document.GetFieldValues();
                    try{fvc.Add("Project Name",GetTokenValue("Project Name").ToString(),true);
                        }catch{};
                    try{fvc.Add("Project Number", GetTokenValue("Project Number").ToString());
                        }catch{};
                    try{fvc.Add("To",GetTokenValue("To").ToString());
                        }catch{};
                    try{fvc.Add("From",GetTokenValue("From").ToString());
                        }catch{};
                    try{fvc.Add("Subject",GetTokenValue("Subject").ToString());
                        }catch{};
                    try{fvc.Add("Date",GetTokenValue("ForEachRow_Date").ToString());
                        }catch{};
        Document.SetFieldValues(fvc);
        Document.SetTemplate(GetTokenValue("TemplateName").ToString());
        Document.Save();
            }catch{}
       }
public string getContentType (string FileExt){
     string ContentType="";
            switch (FileExt)
            {case ".pdf":
                   ContentType =  "application/pdf";
                    break;
                case ".tif":
                     ContentType =  "application/tif";
                    break;
                case ".zip":
                     ContentType =  "application/zip";
                    break;
                case ".dwg":
                     ContentType =  "application/dwg";
                    break;
                case ".msg":
                     ContentType =  "application/msg";
                    break;
                case ".mov":
                     ContentType =  "application/mov";
                    break;
                case ".mp4":
                     ContentType =  "application/mp4";
                    break;
                case ".heic":
                     ContentType =  "application/heic";
                    break;
                case ".rtf":
                     ContentType =  "application/msword";
                    break;
                case ".doc":
                     ContentType =  "application/msword";
                    break;
                case ".docx":
                   ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
             break;
                case ".csv":
                    ContentType = "application/vnd.ms-excel";
                    break;
                case ".xls":
                    ContentType = "application/vnd.ms-excel";
                    break;
                case ".xlsx":
                        ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            break;
            }
            return ContentType;
   // end getContentType
}
    } //end public class
 } //end namespace...

 

Screen Shot 2020-04-17 at 5.07.40 PM.png
0 0

Replies

replied on April 19, 2020

call document.Save() after document.Dispose()

0 0
replied on April 19, 2020

Rich,

Thanks for the reply, the save function is called in line 073, however I did try to move it to line 50 as you recommended but it didn't work. The strange thing is that the code compiles, yet no dice.

Do you think my references are correct?

Screen Shot 2020-04-19 at 9.45.23 PM.png
0 0
replied on April 19, 2020

Oh, I didn’t see the save there. You’d probably want to keep the save at the very end, pass the doc by reference to set template values, and why not change Dispose() to Unlock() - I don’t trust that they mean the same 😀

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.