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

Question

Question

SDK - Error moving a folder into a new folder

SDK
asked on October 1, 2018 Show version history

Hello everyone

I am starting to work with the Laserfiche SDK and I am presented with the following situation in which I want to be guided.

I have the following folder structure:

For example, the file "Alvaro", I need to move it inside the folder "C" and in turn rename it with a new name (Charlie).

The code that I have is the following:

 

private void btnMover_Click(object sender, EventArgs e)
        {
            string nombreViejo = cmbListaExpedientes.Text;
            string nombreNuevo = txtNuevoNombre.Text;
            char primeraLetra = nombreNuevo[0];
            int id = 0;

            RepositoryRegistration ra = new RepositoryRegistration("localhost", "??????");
            Session mySess = new Session();

            try
            {
                mySess.LogIn("?????", "??????", ra);

                Search LFSearch = new Search(mySess);
                LFSearch.Command = "{[General]} & {LF:Name=\""+nombreViejo+"\", Type=\"F\"}";
                LFSearch.Run();

                SearchListingSettings Settings = new SearchListingSettings();
                SearchResultListing Results = LFSearch.GetResultListing(Settings);

                for (int i = 1; i <= Results.RowsCount; i++)
                {
                    id = Convert.ToInt32(Results.GetDatumAsString(i, SystemColumn.Id));
                    FolderInfo folder = Folder.GetFolderInfo(id, mySess);
                    string ruta = "\\Regulados\\" + primeraLetra+ "\\" + nombreNuevo;
                    folder.MoveTo(ruta);
                }
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                mySess.Close();
            }
        }

For the previous example it works correctly, the error that occurs to me is if I try to move the file "Alvaro" to a folder like "F", "G", "H"; a folder that does not exist.

Shows the error "Entry not found".

Can you help me?

0 0

Answer

SELECTED ANSWER
replied on October 1, 2018

Sometimes, you need to create multiple folders in a path, so I usually us code like what is shown in check to see if folder

1 0
replied on October 1, 2018

Haha, that's the correct answer. I started catching the exceptions based on advice from another Laserfiche employee's (who shall go nameless) post.

1 0

Replies

replied on October 1, 2018 Show version history

EDIT: TIL - don't do this. laugh

Unlike Workflow, the SDK will not automatically create folders that don't exist. You need to check for the existence of the destination folder first.

This is how I usually do it.

FolderInfo destFolder;

try
{
	destFolder = Folder.GetFolderInfo(lcrRoot, destFolderPath, session);
}
catch (LaserficheRepositoryException ex)
{
	if (ex.ErrorCode == 9001) //entry not found
	{
		destFolder = Folder.GetFolderInfo(Folder.Create(lcrRoot, destFolderPath, EntryNameOption.AutoRename, session), session);
		destFolder.Unlock();
	}
}

 

1 0
replied on October 1, 2018

Thank you both for the answers, they were very helpful.

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

Sign in to reply to this post.