Help : c# file upload, save to mssql database

Discussion in 'C#' started by Raizern, Feb 16, 2007.

  1. #1
    Hello,

    would anyone please give me example/s on how to make an ASP.NET 2.0 c# script that would upload a file but saves it instead into an mssql database?

    thanks :D
     
    Raizern, Feb 16, 2007 IP
  2. MattD

    MattD Peon

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You'll need to a HTMLInputFile control, and then access the PostedFile object that it reveals.

    The trouble is though that the PostedFile.FileContent attribute is not anything like a byte array - it is actually a stream! The way I did it was to write that stream out to a file in memory (using MemoryStream), then read that back in like you do as any other stream to get the bytes out.

    Once you have the bytes, you can then store the data directly into a blob in the database. You may want to store some other information in there too, such as mimetype.
     
    MattD, Feb 19, 2007 IP
  3. Raizern

    Raizern Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Finally, someone posted something :D

    nice idea, thanks man ... why didnt I realize that :D
     
    Raizern, Feb 19, 2007 IP