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

Question

Question

documentInfo create sdk 9.2

SDK
asked on April 29, 2015 Show version history
Where is the error in this code ? Why getting this error ?

            try
            {
                RepositoryRegistration repositorio = new RepositoryRegistration("192.168.16.6", "ARQDIGITAL");
                Session session = new Session();
                session.LogIn("xxxxx", "xxxxx", repositorio);
                
                foreach (var entry in listaPlanilha)
                {
                    int docID = Document.Create("\\ARQDIGITAL\\014 GESTÃO ADMINISTRATIVA\\014.8 ADMINISTRAÇÃO DE MATERIAL E PATRIMÔNIO\\040.2 CONTROLE PATRIMONIAL\\" + entry.Local,
                        "DEFAULT", EntryNameOption.AutoRename, session);
                    DocumentInfo docInfo = (DocumentInfo)Entry.GetEntryInfo(docID, session);

                    docInfo.SetTemplate("ADM Gestão Patrimonial");

                    FieldValueCollection fvc = new FieldValueCollection();

                    fvc.Add("SEDE", entry.Sede);
                    fvc.Add("DATA AQUISICAO", entry.DataDeAquisicao);
                    fvc.Add("NF", entry.NF);
                    fvc.Add("VALOR DE COMPRA", entry.ValorDeCompra);
                    fvc.Add("DESCRICAO", entry.Descricao);
                    fvc.Add("FABRICANTE", entry.Fabricante);
                    fvc.Add("SEQ CONTROLE", entry.Etiqueta);
                    fvc.Add("Setor", entry.Local);

                    docInfo.SetFieldValues(fvc);
                    docInfo.Save();

                    Console.WriteLine("DOCUMENTO CRIADO NO REPOSITORIO: " + entry.Fabricante);
                }

                session.LogOut();
            }
            catch (Exception ex2)
            {
                FileStream fs1 = new FileStream(@"C:\Users\allan.freitas\Source\Workspaces\Laserfiche\LaserficheArqDigital\bin\Debug" + @"\ERRO_IMPORTACAO.txt", FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter sw1 = new StreamWriter(fs1);

                sw1.BaseStream.Seek(0, SeekOrigin.End);
                sw1.WriteLine("ERRO: escreveu as " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n" + "{0} ", ex2);
                sw1.Flush();
                sw1.Close();   
            }

ERRO: escreveu as 29/04/2015 17:02
Laserfiche.RepositoryAccess.ObjectNotFoundException: Entry not found. [9001]
   em Laserfiche.RepositoryAccess.Entry.MakeDocFolder(String path, String volumeName, EntryType entryType, String lockToken, EntryNameOption options, Session session)
   em Laserfiche.RepositoryAccess.Document.Create(String documentPath, String volumeName, EntryNameOption options, Session session)
   em LaserficheArqDigital.ExcelParaRepositorioArqDigital.Main(String[] args) na c:\Users\allan.freitas\Source\Workspaces\Laserfiche\LaserficheArqDigital\ExcelParaRepositorioArqDigital.cs:linha 87 

0 0

Answer

SELECTED ANSWER
replied on April 30, 2015

Hi there, 

I already find out the solution of the poblem. 

entry.local were null...

0 0
replied on April 30, 2015 Show version history

Allen

You want to access the documentinfo object in a using statement or else make sure that you release it when you are done.  Your code sample does not call a .dispose after you are done indexing, so you will have a memory leak in your app.  With small entry lists, this probably will not be noticeable, but (with your code sample) your documents will remain locked until you log out.  With a large entry list, eventually your code sample will eat up all ram and/or session resources and crash.

0 0

Replies

replied on April 29, 2015

I would do it something like this

                foreach (var entry in listaPlanilha)
                {
                    using (FolderInfo parentFolder = Folder.GetFolderInfo("\\ARQDIGITAL\\014 GESTÃO ADMINISTRATIVA\\014.8 ADMINISTRAÇÃO DE MATERIAL E PATRIMÔNIO\\040.2 CONTROLE PATRIMONIAL\\", session))
                    {
                        using (DocumentInfo docInfo = new DocumentInfo(session))
                        {
                            docInfo.Create(parentFolder, entry.Local, "DEFAULT", EntryNameOption.AutoRename);
                            docInfo.SetTemplate("ADM Gestão Patrimonial");

                            FieldValueCollection fvc = new FieldValueCollection();

                            fvc.Add("SEDE", entry.Sede);
                            fvc.Add("DATA AQUISICAO", entry.DataDeAquisicao);
                            fvc.Add("NF", entry.NF);
                            fvc.Add("VALOR DE COMPRA", entry.ValorDeCompra);
                            fvc.Add("DESCRICAO", entry.Descricao);
                            fvc.Add("FABRICANTE", entry.Fabricante);
                            fvc.Add("SEQ CONTROLE", entry.Etiqueta);
                            fvc.Add("Setor", entry.Local);

                            docInfo.SetFieldValues(fvc);
                            docInfo.Save();
                        }
                    }
                    Console.WriteLine("DOCUMENTO CRIADO NO REPOSITORIO: " + entry.Fabricante);
                }

 

Also, you need to make sure the folder path is correct and created.

1 0
replied on April 29, 2015 Show version history

Thanks Bert, that's an example of the best way to do this, although I would make one change and lift the using (FolderInfo parentFolder = ...) out of the foreach loop. The part that uses DocumentInfo is basically optimum, though.

0 0
replied on April 29, 2015

Michael,  absolutely, I would agree with calling the parent folder before the for loop too (now that you point it out).

I was also guessing that the error was due to the parent not being found, though I did not know about the .NET 4.5 error, so thanks for letting us all know about that.
 

0 0
replied on April 29, 2015

It probably can't find the parent folder. Please make sure you're targeting .NET 4.0 and not .NET 4.5 as there is a defect in RepositoryAccess that causes it to not correctly handle paths with non-ASCII characters in them when targeting .NET 4.5.

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

Sign in to reply to this post.