الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف احفظ مسار رفع ملف pdf في قاعدة البيانات

بدأه ha_2323 في 7 يناير 2012 · 1 رد · 1,037 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندي استفسارين :-

كيف احفظ مسار رفع ملف pdf في قاعدة البيانات انا عملت هذا الكود لكنة يرفع الملف الى المجلد xxx

بس ناقصنا اعمل لة مسار في قاعدة البيانات الى المجلد

If FileUpload1.HasFile Then

FileUpload1.SaveAs(Server.MapPath("xxx\" & FileUpload1.FileName))

MsgBox("save is completed")

الاستفسار الثاني:-

كيف اجعل اداة رفع الملفات(FileUpload1) ان تظهر ملفات فئة معينة (صور - وورد- pdf) قبل الرفع

ياريت حد عندة مثال مرفق

شكرا لكم

#2

هذا الكود بالكامل

 Protected Sub btnAddToCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddToCategory.Click
        'Try
        Dim strGuid As String = ""
        Dim strPicExtension As String = ""
        Dim strFileName As String = ""
        Dim DateAdd As String = DateTime.Now

        '   Firstly upload the picture associated with the news
        If PhotoUpload.HasFile Then
            '   Constructs the picture extension
            strGuid = fnGuid()
            strPicExtension = fnGetPictureExtension(PhotoUpload.FileName)
            strFileName = strGuid & strPicExtension

            '   Add picture to folder
            subAddNewPicture(PhotoUpload, strFileName, "xxx")

            '   Add the record to the database
            UpdateGallery(txtTitle.Text, strFileName, txtMemo.Text.Trim(), DateAdd)

            lblUploadMessage.Text = "تم تحميل  الملف بنجاح .."
            Response.AddHeader("REFRESH", "2;URL=" + ResolveUrl("CNews.aspx"))
        Else
            lblUploadMessage.Text = "اختار الملف .."
        End If

        lblUploadMessage.Visible = True
        ' Catch ex As Exception
        'Throw ex
        '  End Try
    End Sub

#Region "DataLayer"
    Private Sub UpdateGallery(ByVal txtTitle As String, ByVal strFileName As String, ByVal strMemo As String, ByVal DateAdd As String)
        '   Variables declaration
        Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("myConnectionString").ToString()
        Dim sqlConn As New SqlConnection(strConnString)
        Dim sqlcmd As New SqlCommand()

        '   Building the query
        '        Dim sqlQuery_Photo As String = "INSERT INTO [news] VALUES ('" & txtTitle & "', '~/xxx/' +'" & strFileName & "', '" & strMemo & "','" & DateAdd & "')"

        Dim sqlQuery_Photo As String = "INSERT INTO news(Title,path,Description,DateAdd) VALUES ('{0}', '~/xxx/' +'{1}', '{2}','{3}')"

        sqlQuery_Photo = sqlQuery_Photo.Replace("{0}", txtTitle)
        sqlQuery_Photo = sqlQuery_Photo.Replace("{1}", strFileName)
        sqlQuery_Photo = sqlQuery_Photo.Replace("{2}", strMemo)
        sqlQuery_Photo = sqlQuery_Photo.Replace("{3}", DateAdd)


        '   Retrieving search result
        sqlConn.Open()
        sqlcmd.Connection = sqlConn

        '   Adding records to table
        sqlcmd.CommandText = sqlQuery_Photo
        sqlcmd.ExecuteNonQuery()

        sqlConn.Close()
    End Sub
#End Region

#Region "Private Functions"
    '   Adds picture to specified folder
    Private Sub subAddNewPicture(ByVal FileUploader As FileUpload, ByVal strPictureName As String, ByVal strImgFolder As String)
        Dim strImageFolderPath As String
        Dim strImagePath As String

        Try
            '   Construct saving path
            strImageFolderPath = Path.Combine(Request.PhysicalApplicationPath, strImgFolder)
            strImagePath = Path.Combine(strImageFolderPath, strPictureName)

            '   Upload image
            FileUploader.SaveAs(strImagePath)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    '   Function to generate a GUID using current date and time
    Private Function fnGuid() As String
        Dim strGuid As String = ""

        Try
            With Today
                strGuid = .Year & .Month & .Day & Now.Hour & Now.Minute & Now.Second
            End With
        Catch ex As Exception
            Throw ex
        End Try

        '   returning the guid generated
        Return strGuid
    End Function

    '   Returns true if file name has the extension .jpg, .gif, .jpeg
    Private Function fnGetPictureExtension(ByVal strPictureName As String) As String
        Try
            With strPictureName.ToUpper
                If .EndsWith(".JPG") Then
                    Return ".JPG"
                ElseIf .EndsWith(".GIF") Then
                    Return ".GIF"
                ElseIf .EndsWith(".JPEG") Then
                    Return ".JPEG"
                End If
            End With
        Catch ex As Exception
            Throw ex
        End Try

        ' Else if has no extension so it returns ""
        Return ""
    End Function
#End Region

تم تعديل هذه المشاركة بواسطة AboMoayad في 7 يناير 2012 في 14:41

1

اللهم أطل عمري وأحسن عملي واختم بالشهادة أجلي

مواضيع مشابهة