To save an image to a specified path with a randomly generated name

//Here i am assuming that the folder in which you want to store images is “UserPhotos” and  File Uploader control name is    UploadPhoto

string Path = Server.MapPath(“UserPhotos”);

Random r = new Random();

string FileName = r.Next().ToString();

string FileExtention = UploadPhoto.FileName.Substring(UploadPhoto.FileName.LastIndexOf(‘.’));
FileName = FileName + FileExtention;
string FilePath = Path + @”\” + FileName;
UploadPhoto.SaveAs(FilePath);
imgPhoto.ImageUrl = FilePath;

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.