Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Binary to SQL using ASP.NET

Binary to SQL using ASP.NET

Scheduled Pinned Locked Moved ASP.NET
databasequestioncsharpasp-netsql-server
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taurian110
    wrote on last edited by
    #1

    How can I upload Video files to my SQL SERVER database? A code expalme will be highly appreciated. thanks.

    I 1 Reply Last reply
    0
    • T Taurian110

      How can I upload Video files to my SQL SERVER database? A code expalme will be highly appreciated. thanks.

      I Offline
      I Offline
      Ista
      wrote on last edited by
      #2

      ntexg fields will work. 1 line of code equals many bugs. So don't write any!!

      T 1 Reply Last reply
      0
      • I Ista

        ntexg fields will work. 1 line of code equals many bugs. So don't write any!!

        T Offline
        T Offline
        Taurian110
        wrote on last edited by
        #3

        What is ntexg field? While at it I was trying something like this:

            private void UploadFile()
            {
                if (fileUpload.HasFile)
                {
                    string fileExt;
                    fileExt = System.IO.Path.GetExtension(fileUpload.FileName).ToString();
                    //Response.Write(System.IO.Path.GetExtension(fileUpload.FileName).ToString());
                    //Response.Write(fileUpload.FileName
                    Response.Write(fileExt);
                }
            }
            protected void Button1_Click(object sender, EventArgs e)
            {
                UploadFile();
            }
        

        It works for .rm, .img, .doc but when I try the same thing for .MPEG file and pages comes back with nothing! I mean it just dies:confused:, any one know why its doing that?

        T 1 Reply Last reply
        0
        • T Taurian110

          What is ntexg field? While at it I was trying something like this:

              private void UploadFile()
              {
                  if (fileUpload.HasFile)
                  {
                      string fileExt;
                      fileExt = System.IO.Path.GetExtension(fileUpload.FileName).ToString();
                      //Response.Write(System.IO.Path.GetExtension(fileUpload.FileName).ToString());
                      //Response.Write(fileUpload.FileName
                      Response.Write(fileExt);
                  }
              }
              protected void Button1_Click(object sender, EventArgs e)
              {
                  UploadFile();
              }
          

          It works for .rm, .img, .doc but when I try the same thing for .MPEG file and pages comes back with nothing! I mean it just dies:confused:, any one know why its doing that?

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          Here's the vb.net if you need me to translate, maybe I will. Make sure the sql datatype is image. Public Shared Sub SaveFile(ByVal FormID As Integer, ByVal FileName As String, ByVal File As Byte()) Dim conn As New SqlConnection(CStr(Current.Session("ConnectionString"))) Dim cmd As New SqlCommand() cmd.Connection = conn cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "dbo.uspSaveFile" AddFormIDParameter(cmd, FormID) Dim PrmFileImage As New SqlParameter("@File", SqlDbType.Image) PrmFileImage.Direction = ParameterDirection.Input cmd.Parameters.Add(PrmFileImage) PrmFileImage.Value = File Dim PrmFileName As New SqlParameter("@FileName", SqlDbType.VarChar, 100) PrmFileName.Direction = ParameterDirection.Input cmd.Parameters.Add(PrmFileName) PrmFileName.Value = FileName AddNetIDParameter(cmd) conn.Open() cmd.ExecuteNonQuery() conn.Close() End Sub 'Code to save file Dim len As Integer = File1.PostedFile.ContentLength Dim fileContents() As Byte = New Byte(len) {} File1.PostedFile.InputStream.Read(fileContents, 0, len) SaveFile(IntFormID, FileName, fileContents) "People who never make mistakes, never do anything." My Blog

          T 1 Reply Last reply
          0
          • T ToddHileHoffer

            Here's the vb.net if you need me to translate, maybe I will. Make sure the sql datatype is image. Public Shared Sub SaveFile(ByVal FormID As Integer, ByVal FileName As String, ByVal File As Byte()) Dim conn As New SqlConnection(CStr(Current.Session("ConnectionString"))) Dim cmd As New SqlCommand() cmd.Connection = conn cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "dbo.uspSaveFile" AddFormIDParameter(cmd, FormID) Dim PrmFileImage As New SqlParameter("@File", SqlDbType.Image) PrmFileImage.Direction = ParameterDirection.Input cmd.Parameters.Add(PrmFileImage) PrmFileImage.Value = File Dim PrmFileName As New SqlParameter("@FileName", SqlDbType.VarChar, 100) PrmFileName.Direction = ParameterDirection.Input cmd.Parameters.Add(PrmFileName) PrmFileName.Value = FileName AddNetIDParameter(cmd) conn.Open() cmd.ExecuteNonQuery() conn.Close() End Sub 'Code to save file Dim len As Integer = File1.PostedFile.ContentLength Dim fileContents() As Byte = New Byte(len) {} File1.PostedFile.InputStream.Read(fileContents, 0, len) SaveFile(IntFormID, FileName, fileContents) "People who never make mistakes, never do anything." My Blog

            T Offline
            T Offline
            Taurian110
            wrote on last edited by
            #5

            Thank you for your reply, the code works great for every other file but .MPG or .MPEG Do you have any Idea as to why i am unable to work with .MPG/.MPEG?? FYI: I am using ASP.NET 2.0

            T 1 Reply Last reply
            0
            • T Taurian110

              Thank you for your reply, the code works great for every other file but .MPG or .MPEG Do you have any Idea as to why i am unable to work with .MPG/.MPEG?? FYI: I am using ASP.NET 2.0

              T Offline
              T Offline
              Taurian110
              wrote on last edited by
              #6

              Ok well I suspected that the cause might be the size of file so I changed the executionTimeout limit to 900000 and even then I got this message: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.0" Does any one how to use FTP instead of HTTP:confused:? I just read that in a thread and have no clue how to do that!!:wtf: You help will be highly appreciated. Thanks a lot for your replies.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups