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
218 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now