using Laserfiche.DocumentServices; using Laserfiche.RepositoryAccess; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CMISAuthentication { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // < add key = "LFServer" value = "appserver.globalsolgroup.com" /> //< add key = "LFRepository" value = "GSGLF" /> // < add key = "LFUserName" value = "Laserfiche" /> // < add key = "LFPassword" value = "l" /> // < add key = "LFVolume" value = "GSGLF" /> // < add key = "TemplateName" value = "Wagner" /> // < add key = "LFRepoStartPath" value = "Wagner ERP Quotes\\" /> // < add key = "LFRepoMainFolderNameQuote" value = "Quote" /> // < add key = "LFRepoMainFolderNameRFQ" value = "RFQ" /> // string serverName = txtservername.Text.Trim();//Convert.ToString(ConfigurationManager.AppSettings["LFServer"]).Trim(); //string repoName = txtrepositoryname.Text.Trim();//Convert.ToString(ConfigurationManager.AppSettings["LFRepository"]).Trim(); //string username = txtusername.Text.Trim(); //Convert.ToString(ConfigurationManager.AppSettings["LFUserName"]).Trim(); //string password = txtpassword.Text.Trim();//Convert.ToString(ConfigurationManager.AppSettings["LFPassword"]).Trim(); // repository login information string server = "appserver.globalsolgroup.com", repository = "GSGLF"; string username = "Laserfiche", password = "l"; // the document to retrieve metadata from string docPath = "GSGLF\\Wagner ERP Quotes\\Q21-00011-Quotation.pdf"; try { // log into the repository var rr = new RepositoryRegistration(server, repository); using (Session session = new Session()) { session.LogIn(username, password, rr); // retrieve some basic properties of the document DocumentInfo docInfo = Document.GetDocumentInfo(365, session); // get the field values of the document FieldValueCollection fvs = docInfo.GetFieldValues(); // print all the field names and their values for (int i = 0; i < fvs.Count; i++) { string fieldName = fvs.PositionToName(i); object fieldVal = fvs[i]; if(fieldName == "Product_Name") { object[] objProduct_Name = fvs["Product_Name"] as object[]; } FieldInfo f = Field.GetInfo(fieldName, session); string formattedVal = f.ValueToString(fieldVal); Console.WriteLine(fieldName + ":"); Console.WriteLine(formattedVal); Console.WriteLine("\n"); } // log out of the repository session.LogOut(); } Console.WriteLine("Done!"); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); } Console.ResetColor(); Console.WriteLine(); Console.WriteLine("Hit enter to exit."); Console.ReadLine(); } private static FolderInfo CreateHelper(string path, Session s, string lfvolume) { string strmainpath = path; EntryInfo entry = null; Stack toCreate = new Stack(); if (!path.StartsWith("\\")) path = "\\" + path; // This is equivalent to the recursion in the other // solution, but with an explicit stack instead of relying // on the call stack for state. while (entry == null) { toCreate.Push(path.Split('\\').Last()); path = path.Substring(0, path.LastIndexOf('\\')); if (path == "") path = "\\"; entry = Entry.TryGetEntryInfo(path, s); } FolderInfo folder = entry as FolderInfo; if (folder == null) { throw new DuplicateObjectException( "A parent of the requested folder is a non-folder entry."); } // Walk back up the stack as if returning from recursive // calls. FolderInfo parent = null; try { while (toCreate.Count > 0) { if (parent != null) parent.Dispose(); parent = folder; folder = new FolderInfo(s); path = toCreate.Pop(); // folder.Create(parent, path, "DEFAULT", EntryNameOption.None); folder.Create(parent, path, lfvolume, EntryNameOption.None); } } catch (Exception) { // Guarantee that folder does not leak if an Exception // is thrown. if (folder != null) folder.Dispose(); throw; } finally { // Guarantee that parent does not leak. if (parent != null) parent.Dispose(); } return folder; } public class ProductDetails { public string ProductType { get; set; } public string ProductName { get; set; } // public int Quantity { get; set; } // public string Remarks { get; set; } } private void button2_Click(object sender, EventArgs e) { //string server = "appserver.globalsolgroup.com", repository = "GSGLF"; //string username = "Laserfiche", password = "l"; //// the document to retrieve metadata from //string docPath = "GSGLF\\Wagner ERP Quotes\\Q21-00011-Quotation.pdf"; List objProductDetails = new List(); ProductDetails objp1 = new ProductDetails(); objp1.ProductType = "Pratik Arvind"; objp1.ProductName = "Product name"; // objp1.Quantity = 10;//"10"; //objp1.Remarks = "R1"; ProductDetails objp2 = new ProductDetails(); objp2.ProductType = "Vijay Thakor"; objp2.ProductName = "product name my"; // objp2.Quantity = 12;//"Amdavad"; // objp2.Remarks = "R2"; objProductDetails.Add(objp1); objProductDetails.Add(objp2); List productDetails = objProductDetails; //MessageReturns objMessageReturns = new MessageReturns(); string serverName = "appserver.globalsolgroup.com";// Convert.ToString(ConfigurationManager.AppSettings["LFServer"]).Trim(); string repoName = "GSGLF"; // Convert.ToString(ConfigurationManager.AppSettings["LFRepository"]).Trim(); string username = "admin";// Convert.ToString(ConfigurationManager.AppSettings["LFUserName"]).Trim(); string password = "admin"; // Convert.ToString(ConfigurationManager.AppSettings["LFPassword"]).Trim(); string LFVolume = "GSGLF";// Convert.ToString(ConfigurationManager.AppSettings["LFVolume"]).Trim(); string LFRepoStartPath = "Wagner ERP Quotes\\";// Convert.ToString(ConfigurationManager.AppSettings["LFRepoStartPath"]).Trim(); string LFRepoMainFolderNameRFQ = "RFQ";// Convert.ToString(ConfigurationManager.AppSettings["LFRepoMainFolderNameRFQ"]).Trim(); // string LFRepoStartPath = Convert.ToString(ConfigurationManager.AppSettings["LFRepoStartPath"]).Trim(); //string NPSDoc = Convert.ToString(ConfigurationManager.AppSettings["NPSPath"]).Trim(); //List wagnerImportData1 = new List(); //string strlocalpath = @"C:\\mihir vyas\\PDFFolder"; // initialize an instance of List to store the search results //List contents = new List(); // log into the repository RepositoryRegistration repository = new RepositoryRegistration(serverName, repoName); Session session = new Session(); // WagnerImportData wagnerImportData = new WagnerImportData(); // string strcomm = ""; // string strtxt1; try { if (productDetails != null) { session.LogIn(username, password, repository); FieldValueCollection fieldValues = new FieldValueCollection(); if (productDetails != null) { if (productDetails.Count > 0) { List valueListProductType = new List(); List valueListProductName = new List(); for (int i = 0; i < productDetails.Count; i++) { valueListProductType.Add(productDetails[i].ProductType.ToString()); valueListProductName.Add(productDetails[i].ProductName.ToString()); } object[] valueProductType = valueListProductType.ToArray(); object[] valuesProductName = valueListProductName.ToArray(); fieldValues.AppendValues("Product_Type", valueProductType); fieldValues.AppendValues("Product_Name", valuesProductName); } } if ("1" == "1") // thumb image { string folderPath = LFRepoStartPath + "\\" + LFRepoMainFolderNameRFQ; EntryInfo entry = Entry.TryGetEntryInfo(folderPath, session); if (entry != null) { FolderInfo folder = entry as FolderInfo; if (folder != null) { //return folder; } else { throw new DuplicateObjectException("Object already exists"); } } else { CreateHelper(folderPath, session, LFVolume); } FolderInfo lfFolder = Folder.GetFolderInfo(folderPath, session); string fileName = "MYname1111.pdf"; // file name int NewDocID = Laserfiche.RepositoryAccess.Document.Create(lfFolder, fileName, EntryNameOption.Overwrite, session); DocumentImporter DI = new DocumentImporter(); DocumentInfo newDoc = new DocumentInfo(NewDocID, session); try { // fieldValues.TemplateName. = "TestTemplate"; // newDoc newDoc.SetTemplate("TestTemplate", fieldValues, true); newDoc.Save(); } catch (Exception ex) { ICollection ILFCollection = newDoc.GetBadFieldValues();// new BadFieldValue(); } DI.Document = newDoc; //Stream fileStream = new MemoryStream(byteArray); DI.OverwritePages = false; // string contentType = "application/pdf"; //string contentType = (contentType == null) ? "application/pdf" : contentType; //DI.ImportEdoc(contentType, wagnerImportData.FilePath); // final import document on repository //string folderpath = "C:\\Mihir Test\\1\\ABC.pdf"; // Byte[] filebyte = File.ReadAllBytes(folderpath); // WagnerRFQTemplate.FileByte = filebyte; // WagnerRFQTemplate.FileName = "ABC.pdf"; //if (WagnerRFQTemplate.FileByte != null) //{ // Stream stream = new MemoryStream(WagnerRFQTemplate.FileByte); // DI.ImportEdoc(contentType, stream); // final import document on repository // //DI.ImportEdoc(contentType, strmp4path); // final import document on repository //} } //end apply metadata // log out of the repository // if (session != null) // session.LogOut(); // objMessageReturns.status = true; // objMessageReturns.message = "LF Data saved"; ;// ex.Message.ToString(); //string jsonstring = JsonConvert.SerializeObject(objMessageReturns);//, Newtonsoft.Json.Formatting.Indented); //return objMessageReturns; } else { //objMessageReturns.status = false; // objMessageReturns.message = "Web Service Object is null";// ex.Message.ToString(); // string jsonstring = JsonConvert.SerializeObject(objMessageReturns);//, Newtonsoft.Json.Formatting.Indented); //return objMessageReturns; } } catch (Exception ex) { var lineNumber = 0; const string lineSearch = ":line "; var index = ex.StackTrace.LastIndexOf(lineSearch); if (index != -1) { var lineNumberText = ex.StackTrace.Substring(index + lineSearch.Length); if (int.TryParse(lineNumberText, out lineNumber)) { } } // objMessageReturns.status = false; // objMessageReturns.message = "My Exception : " + ex.Message.ToString() + "line number-" + lineNumber; //string jsonstring = JsonConvert.SerializeObject(objMessageReturns);//, Newtonsoft.Json.Formatting.Indented); // return objMessageReturns; } finally { if (session != null) { session.LogOut(); } session.Discard(); session.Close(); //WagnerRFQTemplate = null; } } } }