Question

I'm using a save file dialog to save an excel file from my data grid view and I want to save a file in a folder in My Documents. Then, if that folder is not existing, the folder will be created. How do I do that?

Était-ce utile?

La solution

Dim myDocs = My.Computer.FileSystem.SpecialDirectories.MyDocuments

Dim dataDir = IO.Path.Combine(myDocs,"Data")


If Not IO.Directory.Exists(dataDir) Then IO.Directory.Create(dataDir)

fileDialog.InitialDirectory = dataDir


fileDialog.ShowDialog()

Autres conseils

You can add your file path in we.config like this
  <appSettings>
    <add key="imagePath" value="D:\Image\Profile" />
  </appSettings>

And then in code write this:

string strVirtualPath = ConfigurationManager.AppSettings["imagePath"];

if (!System.IO.Directory.Exists(strVirtualPath))
{
   System.IO.Directory.CreateDirectory(strVirtualPath);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top