Click here to Skip to main content
15,564,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,
when i select the word or image from the local folder using browse in dotnet and if i click the submit button it should create the new folder (the name should be filename with current month) and the files should be stored within that new folder.

for eg, my folder will be - images/

if i want to upload the word or images - the images should be stored like this (images/february/ws.doc).


can anyone help me to do
Posted
Updated 24-Feb-11 3:17am
v2
Comments
senguptaamlan 24-Feb-11 8:09am    
please explain with an example...not getting the proper problem statement

Try something like:

C#
void Save(string sourceFilePath, string destinationRootDirectory)
{
    //create the destination directory
    string currentMonth = DateTime.Now.ToString("MMMM");
    string destinationDirectory = destinationRootDirectory + @"\images\" + currentMonth;
    Directory.CreateDirectory(destinationDirectory);

    //copy the source file to that directory
    string shortFileName = Path.GetFileName(sourceFilePath);
    string destinationFilePath = destinationDirectory + @"\" + shortFileName;
    File.Copy(sourceFilePath, destinationFilePath);
}
 
Share this answer
 
Comments
Espen Harlinn 25-Feb-11 5:37am    
As OP is using ASP.NET, he probably need to map the resulting path, and adjust the security settings for his web application - you may want to update your answer to reflect this, and I'll vote on it at that time :)
Olivier Levrey 25-Feb-11 5:41am    
Well, I don't know anything about ASP.NET. I wrote this answer because I supposed it was just a C# problem. So feel free to improve my answer or even add yours.
Espen Harlinn 25-Feb-11 6:18am    
As my answer obviously builds on yours - my 5
Olivier Levrey 25-Feb-11 8:42am    
thanks ;)
To implement the methods described by Olivier Levrey, you will probably need to use HttpServerUtility.MapPath[^] to get a physical path for your files. Put a '/' at the beginning of the path to indicate an absolute virtual path to the site.

You will also need to ensure that the IIS user context for your web application has the required access rights to manipulate the filesystem.

Regards
Espen Harlinn
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900