I am using the <input type="file" />
tag to upload a file to the server. How do I access the file at the server side and store it at the server? (The file is an image file)
The client side code is :
<form id="form1" action="PhotoStore.aspx" enctype="multipart/form-data">
<div>
<input type="file" id="file" onchange="preview(this)" />
<input type="submit" />
</div>
</form>
Photostore.aspx.cs has
protected void Page_Load(object sender, EventArgs e)
{
int index = 1;
foreach (HttpPostedFile postedFile in Request.Files)
{
int contentLength = postedFile.ContentLength;
string contentType = postedFile.ContentType;
string fileName = postedFile.FileName;
postedFile.SaveAs(@"c:\test\file" + index + ".tmp");
index++;
}
}
I tried uploading a jpg file. Not able to see a saved file. What is going wrong?