File Upload for asp.net in c#
I have been working on an image/file uploader that stores an image to a virtual directory with MapPath or to a database. I have been using if statements for the button click event to check the file and attempt to save but I have not been successful.
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string extension = Path.GetExtension(FileUpload1.FileName);
if (ext开发者_开发问答ension == ".jpg" || extension == ".gif" || extension == ".png" || extension == ".bmp")
{
FileUpload1.SaveAs(Server.MapPath("../photos/" + FileUpload1.FileName));
string imagePath = "/photos/" + FileUpload1.FileName;
please try this
FileUpload1.SaveAs(Server.MapPath(@"~\photos\" + FileUpload1.FileName));
精彩评论