开发者

Upload and view the images

In my web page I have开发者_StackOverflow the image box and upload button. When I click the upload button, the folder browser will open and if I select the image, it should display in the image box. I am using ASP.Net and VB.Net


I don't think we can display a Folder browser dialog from WebPage. Also Folder browser dialog used to select Folder, not Files. You need to use Open File Dialog.

You can do it with a File Upload Control. Check this link for more info : http://msdn.microsoft.com/en-us/library/aa478971.aspx

Sample Code

protected void UploadButton_Click(object sender, EventArgs e)
{
    String savePath = @"c:\temp\uploads\";

    if (FileUpload1.HasFile)
    {
    String fileName = FileUpload1.FileName;
    savePath += fileName;
    FileUpload1.SaveAs(savePath);
    UploadStatusLabel.Text = "Your file was saved as " + fileName;
    Image1.ImageUrl = fileName;
    }
    else
    {      
    UploadStatusLabel.Text = "You did not specify a file to upload.";
    }  
}

Source : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜