SaveLayoutToStream. Error: Could not find part of the path "c: \ TreeListLayout \"

I try to run an example - link
User - admin
Scenario:
  - I expand the treelist node;
  - I execute the "SaveLayoutToStream_mtd ()" method;

I get in line

System.IO.FileStream outFile = new System.IO.FileStream(fileName, System.IO.FileMode.Create);

an error

System.IO.DirectoryNotFoundException: "Could not find part of the path" c: \ TreeListLayout \ "."

all code

string fileName = @"c:\TreeListLayout\";
public void SaveLayoutToStream_mtd()
{            
    System.IO.FileStream outFile = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
    treeList1.SaveLayoutToStream(outFile);
    outFile.Close();
}

How to fix the error?

1 answer

  • answered 2018-11-08 07:45 Nico Haase

    Have you seen the difference between your code and the example you've referenced? You are trying to write to a file with the invalid name c:\TreeListLayout\ - that is a directory name. Either remove the trailing slash or append a file name