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?
Asked
Active
Viewed 1,314 times
2 Answers
2
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()

jcwrequests
- 1,132
- 1
- 7
- 13
-1
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);
}

Zainab
- 25
- 3