使用ASP.NET上传图片问题 [英] Upload Image Problem using ASP.NET

查看:78
本文介绍了使用ASP.NET上传图片问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个简单的上载图像代码,单击上载"按钮时不起作用.因此,当我重新启动程序并查看该图像上载了什么内容时,可能发生回发问题或缓存,因此我该怎么办做,我已经使用了这个ASP语法

Hi,
I have a simple upload image code,It does not works when I click on the Upload button.So when I restart my program and see what that image is uploaded whats happening here,There may be post back issue or caching,so what should I do,I have use this ASP Syntax

<asp:FileUpload ID="fuImage" Width="320" EnableTheming=true runat="server"  Visible="true" />  <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><asp:Button runat="server" ID="btnUploadImage" OnClick="UploadImage" Text="Upload Facility Image" Visible="true" ></asp:Button></font>
           </td>


Protected Sub UploadImage(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim saveDir As String = ConfigurationManager.AppSettings.Item("BaseApplicationFolder")

            ' Get the physical file system path for the currently
            ' executing application.
            Dim appPath As String = Request.PhysicalApplicationPath
            If Not FACID = txtFacId.Text And Not String.IsNullOrEmpty(txtFacId.Text) Then
                FACID = txtFacId.Text
            End If
            ' Before attempting to save the file, verify
            ' that the FileUpload control contains a file.
            If (fuImage.HasFile) Then
                Dim savePath As String = appPath + "_images\assisted_living\fac_profile_pic\" + _
                    Server.HtmlEncode(fuImage.FileName)
                     If fuImage.FileName.Contains(FACID) Then

                    ' Call the SaveAs method to save the uploaded file to the specified path. 
                    ' If a file with the same name already exists in the specified path, the uploaded file overwrites it.
                    If (File.Exists(savePath)) Then

                        File.Delete(savePath)

                    End If

                    fuImage.SaveAs(savePath)
                    Fac_picture.ImageUrl = "..\..\_images\assisted_living\fac_profile_pic\" + FACID + ".jpg"

                    fuImage.DataBind()

                Else
                    lbl_message.Text = "The image name and facility name should match."
                End If

            End If
        Catch ex As Exception
            lbl_message.Text = ex.Message
        End Try

    End Sub

推荐答案

是的,这是页面刷新的问题,所以我将此行添加到了Aspx页面中,并在页面刷新时加载了图像.
谢谢你.
< meta http-equiv =刷新" content ="10"/>
Yes It Was a Matter of Page refresh So I added this line into the Aspx page And As page refresh Image loads.
Thank you.
<meta http-equiv="Refresh" content="10" />


这篇关于使用ASP.NET上传图片问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆