开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜