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
232 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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