Solved

when i save a file, if the parent directory doesn't exist i want my save to crete what's missing in my path

Posted on 2007-11-14
5
225 Views
Last Modified: 2010-04-15
what to add, knowing that the todayDate folder doesnt existe.
i need to save the file in a brand new folder which name is for instance 2007_11_14.


string targetFile = PathToExcelRepository + VarSession.Community + "/containers/"  +todayDate+ "/" + FileNameToUpload;

      if(!File.Exists(targetFile))
      {
            fileUpload.PostedFile.SaveAs(targetFile);


received error:
Could not find a part of the path "C:\Documents and Settings\Erwin\My Documents\Visual Studio Projects\e-plan\E-pla.....
0
Comment
Question by:toshi_
5 Comments
 
LVL 8

Accepted Solution

by:
doraiswamy earned 450 total points
ID: 20279425
 String DirName = Path.GetDirectory(targetfile);
  if(!Directory.Exists (DirName)
    {
    Directory.Create(DirName);
    }
  if(!File.Exists(targetfile))
   {
  //  ....
   }
0
 
LVL 11

Expert Comment

by:cmhunty
ID: 20279427
You'll have to get the full path to the file and then test the path, so

Dim strPathToFile As String = PathToExcelRepository + VarSession.Community + "/containers/"  +todayDate+ "/"
Dim di As New DirectoryInfo(strPathToFile)
If di.Exists = False
   di.Create()
End If

Then you can continue with your code
0
 
LVL 8

Expert Comment

by:doraiswamy
ID: 20279436
cmhunty, this is the C# topic area.
0
 
LVL 7

Assisted Solution

by:bungHoc
bungHoc earned 50 total points
ID: 20279440
System.IO.Directory.CreateDirectory(@"C:\Something\SomethingElse\AnotherThing");

This creates all sub directories too (if needed)
0
 

Author Comment

by:toshi_
ID: 20279798
you're all kings guys !!!!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question