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. Advertising

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,173
    Chris
    May 9, 2006
  2. Islamegy®

    FormView and FileUpload

    Islamegy®, May 17, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    7,463
    Islamegy®
    May 18, 2006
  3. J055
    Replies:
    4
    Views:
    17,590
    Walter Wang [MSFT]
    Sep 15, 2006
  4. Chris
    Replies:
    5
    Views:
    515
    Jon Paal [MSMD]
    Mar 31, 2007
  5. RosH
    Replies:
    0
    Views:
    450
Loading...

Share This Page