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...