FileUpload Control in FormView using ObjectDataSource

Discussion in 'ASP .Net' started by =?Utf-8?B?Z292ZXI=?=, Sep 2, 2007.

  1. Hello,
    I have a Formview in insert mode with a fileUpload control on it. I'm
    trying to get the contents of the uploaded file passed to my ObjectDataSource
    to be persisted to my database. The Method called by the Insert method takes
    a parametare called DocBlob of type byte[] for the file contents. When I
    generate an object datasource using this method, it generates the parameter
    below:
    <asp:parameter Name="DocBlob" Type="Object" />

    Now in the item inserting event of my ObjectDatasource, I need to set the
    value of this paramater (because i can't Bind to the contents of a
    fileupload).

    I get the bytes of the uploaded files by using upLoadFile.FileBytes wihich
    is of type byte[]. My Method takes a Byte[] also. so far so good ... I got
    a byte[] and my Insermethod needs a byte[].

    Now I need to pass the fiename and contents from my aspx to my insert method
    via the Objectdatasource.
    for the filename i use this code :
    ObjectDataSourceFormView.InsertParameters["FileName"].DefaultValue =
    upLoadFile.FileName;

    but for the DocBlob byte[] I cant do this. The DefauktValue needs to be a
    string, I cant set it to a byte[];

    Can anyone offer some advice? I tried overloading my insrt method and gav a
    version that took a string, converted it to a byte[] the called my original
    method, but i couldnd firgure out how to properly encode an uploaded file as
    a string. I tried UTF8Encoding and UTF32Encoding, but neither worked.

    I;m thinkning i should just give up on the Object datasource and call my
    method directly.
     
    =?Utf-8?B?Z292ZXI=?=, Sep 2, 2007
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    0
    Views:
    1,241
    Chris
    May 9, 2006
  2. Islamegy®

    FormView and FileUpload

    Islamegy®, May 17, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    7,651
    Islamegy®
    May 18, 2006
  3. marygfrc

    Formview error with fileupload

    marygfrc, Jun 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    471
    marygfrc
    Jun 15, 2006
  4. J055
    Replies:
    4
    Views:
    17,823
    Walter Wang [MSFT]
    Sep 15, 2006
  5. Chris
    Replies:
    5
    Views:
    713
    Jon Paal [MSMD]
    Mar 31, 2007
  6. RosH
    Replies:
    0
    Views:
    548
  7. bogdan
    Replies:
    2
    Views:
    644
    bogdan
    Mar 24, 2008
  8. Chris

    Referencing the fileupload in formview

    Chris, May 9, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    176
    Chris
    May 9, 2006
Loading...