Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在asp.net中上载照片_Asp.net_Vb.net - Fatal编程技术网

在asp.net中上载照片

在asp.net中上载照片,asp.net,vb.net,Asp.net,Vb.net,你好,我有下面的代码为我的应用程序上传图片。我想在此代码中添加一行或多行代码,以显示这样的成功消息“图片已成功上载” 我知道我需要添加一个标签控件来显示消息,但我不知道如何操作。代码如下: Imports System.Data Imports System.IO Imports System.Data.SqlClient Partial Class PhotoAdmin_Default Inherits System.Web.UI.Page Protected Sub P

你好,我有下面的代码为我的应用程序上传图片。我想在此代码中添加一行或多行代码,以显示这样的成功消息“图片已成功上载”

我知道我需要添加一个标签控件来显示消息,但我不知道如何操作。代码如下:

Imports System.Data
Imports System.IO
Imports System.Data.SqlClient

Partial Class PhotoAdmin_Default
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        UserIdValue.Text = Membership.GetUser().ProviderUserKey.ToString()
        cannotUploadImageMessage.Visible = False

    End Sub


    Protected Sub dvPictureInsert_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvPictureInsert.ItemInserted
        'If the record was successfully inserted, save the picture
        If e.AffectedRows > 0 Then
            'Determine the maximum pictureID for this user
            Dim results As DataView =
                CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), 
                    DataView)

            Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer)

            'Reference the FileUpload control
            Dim imageUpload As FileUpload =
                CType(dvPictureInsert.FindControl("imageUpload"), FileUpload)

            If imageUpload.HasFile Then
                Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")

                imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg")
            End If

        End If
    End Sub



    Protected Sub dvPictureInsert_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvPictureInsert.ItemInserting
        Dim cancelInsert As Boolean = False


        Dim imageUpload As FileUpload =
            CType(dvPictureInsert.FindControl("imageUpload"), FileUpload)

        If Not imageUpload.HasFile Then
            cancelInsert = True
        Else
            If Not imageUpload.FileName.ToUpper().EndsWith(".JPG") Then
                cancelInsert = True 'Invalid image file!

            End If
        End If

        If cancelInsert Then
            e.Cancel = True
            cannotUploadImageMessage.Visible = True
        End If

        'Set the UserId value to the currently logged on user's ID
        e.Values("UserId") = Membership.GetUser().ProviderUserKey

        'Set the UploadedOn value to the current date/time
        e.Values("UploadedOn") = DateTime.Now
    End Sub

    Protected Sub gvPictures_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles gvPictures.RowDeleted
        Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")
        Dim fileName As String = baseDirectory &
            e.Keys("PictureID") & ".jpg"
        File.Delete(fileName)
    End Sub

这个问题已经得到了回答,感谢上帝为这个论坛。这真的很有帮助,言语无法表达。 答案来自:

您必须在“dvPictureInsert\u ItemInserted”事件中显示消息。如需更多参考,请参阅此链接,在该链接中,您可以看到示例部分,您可以获得您必须执行的操作


你好,Josh,你能帮我做这个吗。我有几个问题要问,但是我对asp.NET有点陌生。谢谢你,日期/时间已经更新了。你真是一个幸运儿。你能帮我吗:我希望上传的照片显示这样的成功消息“图片已成功上传。你能帮我吗?”?