Reputation: 4280
In my web application, I need to be able to allow users to upload and download their images. How can this be don in ASP.net?
I want to user to be able to sign in (I already have that done) and be able to upload images to their account. Later on, I want them to be able to download them.
Thanks
Upvotes: 2
Views: 1038
Reputation: 73301
You can also use
<asp:FileUpload runat="server" id="upImage" Width="575px" CssClass="txt-Normal"></asp:FileUpload>
Here is my method to save them to a location on the site.
string completeFilePath = this.Request.PhysicalApplicationPath + System.Configuration.ConfigurationManager.AppSettings["ImageUploadPath"];
if (System.IO.Directory.Exists(completeFilePath))
{
System.IO.Directory.CreateDirectory(completeFilePath);
}
if (!System.IO.File.Exists(completeFilePath + this.upImage.FileName))
{
this.upImage.SaveAs(completeFilePath + this.upImage.FileName);
}
imageUrl = string.Format("~{0}{1}", System.Configuration.ConfigurationManager.AppSettings["ImageUploadPath"], this.upImage.FileName);
Upvotes: 1
Reputation: 9905
If the images are of a reasonable size, (e.g. less than a few MB), you can do this with a <input type=file> tag. Set the encoding of your form tag to multipart/form-data and implement some code-behind to get a hold of the file.
See the ASP.Net videos (Part 1) and (Part 2) for a detailed example.
Hope this helps!
Upvotes: 1