开发者

File Upload for asp.net in c#

开发者 https://www.devze.com 2023-01-28 02:13 出处:网络
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 an

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消