Sunday, 30 December 2012 16:54

how to upload images to server creating new directory

Written by 
Rate this item
(0 votes)

the following codes uses FileUpload control to
upload file to server.it's a example for
uploading files to the server using asp.net
and c#.

it first checks whether a folder exists
or not where files will be uploaded.if the folder
not exists then it creates the directory.then
the file is saved using FileUpload contol
to the correct directory in server -

string subPath = "ImagesPath"; // your code goes here
bool IsExists = System.IO.Directory.Exists(Server
.MapPath(subPath));
if (!IsExists) System.IO.Directory.CreateDirectory
(Server.MapPath(subPath));

FileUpload FileUpload1 = FileUploadd;
string virtualFolder = "~/"+subPath+"/";
string physicalFolder = Server.MapPath(virtualFolder);
FileUpload1.SaveAs(physicalFolder + FileUpload1.FileName);

Read 1160 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments