FileUpload Control in FormView using ObjectDataSource

G

Guest

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top