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

Independent Software Vendors: 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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

627 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