How to create a folder in server and rename files
Hello friends..,
Greetings!!!!!
I have an application(client) from which i upload files to the server. I did that upload part. But now i have a problem with that. In my application different users login and upload their files. For each user their will be seperate login.
The problem is that i need to create a folder in the server spontaneously when a particular user tries to upload a file and also i need to rename that file when it is saved in that folder so that if the user tries to upload a file again with the same name it should not be overwritted.I am giving the code that i used to upload below:
protected void Button1_ServerClick(object sender, EventArgs e)
{
//Uploading the attached file
if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileNa me);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("file Uploaded");
}
catch (Exception ex)
{
Response.Write("Error:" + ex.message);
//Note: Exception.Message returns a detailed message that describes the current exception.
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
so guys please help me for the above problem as early as possible.
Thanks & Regards,
Pramod.
|