471,056 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,056 software developers and data experts.

Formview FileUpload and ObjectDataSource

I want do my insert to a database using a formview bound to an
objectdatasource. I also want to upload a file. I'm quite new to and this is
just test code but Is there any way I can pass the file as a byte array and
manipulate it in my business object. Currently what I have is this, but my
byte array in my business object is nothing. It's like it's not passed the
file as a stream. I think I am not binding the FileUpload to the
insertparameter but I don't know how to fix it. Regards, Chris.
<asp:FormView ID="frmvwCustomer" runat="server" DataSourceID="objdsCustomer"
DefaultMode="Insert" AllowPaging="True">

<InsertItemTemplate>

Name<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />

Email<asp:TextBox ID="txtemail" Text="<%# Bind('strEmail') %>"
runat="server"></asp:TextBox><br />

CV<asp:FileUpload ID="CV" runat="server" /><br />

&nbsp;<asp:Button ID="Button1" runat="server" CommandName="Insert"
Text="Button" />

</InsertItemTemplate>

</asp:FormView>
</div>

<asp:ObjectDataSource ID="objdsCustomer" runat="server"
InsertMethod="createcustomer"

SelectMethod="getcustomer_list" TypeName="Customer">

<InsertParameters>

<asp:Parameter Name="strName" Type="Object" />

<asp:Parameter Name="strEmail" Type="Object" />

<asp:Parameter Name="CV" Type="Object" />

</InsertParameters>

</asp:ObjectDataSource>

Public Sub createcustomer(ByVal strname As String, ByVal strEmail As String,
ByVal cv() As Byte)

End Sub
Mar 31 '07 #1
6 7171
some sample code here may help

http://www.superexpert.com/Books/Asp...ting11_26.aspx
http://vinayakshrestha.wordpress.com...ad-workaround/

general formview info is here:

http://msconline.maconstate.edu/tuto...20/default.htm


"Chris" <no****@nospam.comwrote in message news:uK**************@TK2MSFTNGP06.phx.gbl...
>I want do my insert to a database using a formview bound to an objectdatasource. I also want to upload a file. I'm quite new to and
this is just test code but Is there any way I can pass the file as a byte array and manipulate it in my business object. Currently
what I have is this, but my byte array in my business object is nothing. It's like it's not passed the file as a stream. I think I
am not binding the FileUpload to the insertparameter but I don't know how to fix it. Regards, Chris.
<asp:FormView ID="frmvwCustomer" runat="server" DataSourceID="objdsCustomer" DefaultMode="Insert" AllowPaging="True">

<InsertItemTemplate>

Name<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />

Email<asp:TextBox ID="txtemail" Text="<%# Bind('strEmail') %>" runat="server"></asp:TextBox><br />

CV<asp:FileUpload ID="CV" runat="server" /><br />

&nbsp;<asp:Button ID="Button1" runat="server" CommandName="Insert" Text="Button" />

</InsertItemTemplate>

</asp:FormView>
</div>

<asp:ObjectDataSource ID="objdsCustomer" runat="server" InsertMethod="createcustomer"

SelectMethod="getcustomer_list" TypeName="Customer">

<InsertParameters>

<asp:Parameter Name="strName" Type="Object" />

<asp:Parameter Name="strEmail" Type="Object" />

<asp:Parameter Name="CV" Type="Object" />

</InsertParameters>

</asp:ObjectDataSource>

Public Sub createcustomer(ByVal strname As String, ByVal strEmail As String, ByVal cv() As Byte)

End Sub


Mar 31 '07 #2
I 've got something like that working. My problem is that I want to put all
logic, and that would include manipulating the uploaded file in a business
object, preferably one method. Putting that code on the page with the
control doesn't seem very 3 tier, which is what I was aiming for. Really I
want to grab the stream rather than file the control.

I got something like this working ages ago but I've lost the code. I seem to
remember being able to specify the type as filebytes though.

"Jon Paal [MSMD]" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:eU**************@TK2MSFTNGP04.phx.gbl...
some sample code here may help

http://www.superexpert.com/Books/Asp...ting11_26.aspx
http://vinayakshrestha.wordpress.com...ad-workaround/

general formview info is here:

http://msconline.maconstate.edu/tuto...20/default.htm


"Chris" <no****@nospam.comwrote in message
news:uK**************@TK2MSFTNGP06.phx.gbl...
>>I want do my insert to a database using a formview bound to an
objectdatasource. I also want to upload a file. I'm quite new to and this
is just test code but Is there any way I can pass the file as a byte array
and manipulate it in my business object. Currently what I have is this,
but my byte array in my business object is nothing. It's like it's not
passed the file as a stream. I think I am not binding the FileUpload to
the insertparameter but I don't know how to fix it. Regards, Chris.
<asp:FormView ID="frmvwCustomer" runat="server"
DataSourceID="objdsCustomer" DefaultMode="Insert" AllowPaging="True">

<InsertItemTemplate>

Name<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />

Email<asp:TextBox ID="txtemail" Text="<%# Bind('strEmail') %>"
runat="server"></asp:TextBox><br />

CV<asp:FileUpload ID="CV" runat="server" /><br />

&nbsp;<asp:Button ID="Button1" runat="server" CommandName="Insert"
Text="Button" />

</InsertItemTemplate>

</asp:FormView>
</div>

<asp:ObjectDataSource ID="objdsCustomer" runat="server"
InsertMethod="createcustomer"

SelectMethod="getcustomer_list" TypeName="Customer">

<InsertParameters>

<asp:Parameter Name="strName" Type="Object" />

<asp:Parameter Name="strEmail" Type="Object" />

<asp:Parameter Name="CV" Type="Object" />

</InsertParameters>

</asp:ObjectDataSource>

Public Sub createcustomer(ByVal strname As String, ByVal strEmail As
String, ByVal cv() As Byte)

End Sub



Mar 31 '07 #3
I 've got something like that working. My problem is that I want to put all
logic, and that would include manipulating the uploaded file in a business
object, preferably one method. Putting that code on the page with the
control doesn't seem very 3 tier, which is what I was aiming for. Really I
want to grab the stream rather than file the control.

I got something like this working ages ago but I've lost the code. I seem to
remember being able to specify the type as filebytes though.

"Jon Paal [MSMD]" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:eU**************@TK2MSFTNGP04.phx.gbl...
some sample code here may help

http://www.superexpert.com/Books/Asp...ting11_26.aspx
http://vinayakshrestha.wordpress.com...ad-workaround/

general formview info is here:

http://msconline.maconstate.edu/tuto...20/default.htm


"Chris" <no****@nospam.comwrote in message
news:uK**************@TK2MSFTNGP06.phx.gbl...
>>I want do my insert to a database using a formview bound to an
objectdatasource. I also want to upload a file. I'm quite new to and this
is just test code but Is there any way I can pass the file as a byte array
and manipulate it in my business object. Currently what I have is this,
but my byte array in my business object is nothing. It's like it's not
passed the file as a stream. I think I am not binding the FileUpload to
the insertparameter but I don't know how to fix it. Regards, Chris.
<asp:FormView ID="frmvwCustomer" runat="server"
DataSourceID="objdsCustomer" DefaultMode="Insert" AllowPaging="True">

<InsertItemTemplate>

Name<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />

Email<asp:TextBox ID="txtemail" Text="<%# Bind('strEmail') %>"
runat="server"></asp:TextBox><br />

CV<asp:FileUpload ID="CV" runat="server" /><br />

&nbsp;<asp:Button ID="Button1" runat="server" CommandName="Insert"
Text="Button" />

</InsertItemTemplate>

</asp:FormView>
</div>

<asp:ObjectDataSource ID="objdsCustomer" runat="server"
InsertMethod="createcustomer"

SelectMethod="getcustomer_list" TypeName="Customer">

<InsertParameters>

<asp:Parameter Name="strName" Type="Object" />

<asp:Parameter Name="strEmail" Type="Object" />

<asp:Parameter Name="CV" Type="Object" />

</InsertParameters>

</asp:ObjectDataSource>

Public Sub createcustomer(ByVal strname As String, ByVal strEmail As
String, ByVal cv() As Byte)

End Sub



Mar 31 '07 #4
I may be missing your objective, but it seems that a formview, and associated upload control, would be dealt with through an event
handler (code beside or in page) rather than a business object layer...

Mar 31 '07 #5
What I mean is that I don't want to put business logic about e.g. where an
object is saved in the presentation layer. If this is something that you
can't really acheive with the formview/objectdatasorce I have a work around
it's not very good but I have posted it. A cleaner solution is to bind the
the stream to byte array and use that in the business layer.

My slightly hacky work around is to tell pass the business object the name
of the formview and fileupload and it find it on the page. It works but I
don't like it....

<form id="form1" runat="server" enctype="multipart/form-data">
<div>
&nbsp;<asp:FormView ID="frmvwCustomer" runat="server"
DataSourceID="objdsCustomer" DefaultMode="Insert" AllowPaging="True">
<InsertItemTemplate>
Name<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />
Email<asp:TextBox ID="txtemail" Text="<%# Bind('strEmail') %>"
runat="server"></asp:TextBox><br />
CV<asp:FileUpload ID="CV" runat="server" /><br />
&nbsp;<asp:Button ID="Button1" runat="server" CommandName="Insert"
Text="Button" />
</InsertItemTemplate>
</asp:FormView>
</div>
<asp:ObjectDataSource ID="objdsCustomer" runat="server"
InsertMethod="createcustomer"
SelectMethod="getcustomer_list" TypeName="Customer">
<InsertParameters>
<asp:Parameter Name="strname" Type="String" />
<asp:Parameter Name="strEmail" Type="String" />
<asp:Parameter Name="formview" DefaultValue="frmvwCustomer" Type="String" />
<asp:Parameter Name="upload" DefaultValue="CV" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
</form>
Public Sub createcustomer(ByVal strname As String, ByVal strEmail As String,
ByVal formview As String, ByVal upload As String)
Dim page As Page = HttpContext.Current.CurrentHandler
Dim frmvw As FormView = CType(page.FindControl(formview), FormView)
Dim fileup As FileUpload = CType(frmvw.FindControl(upload), FileUpload)
Dim cv() As Byte = fileup.FileBytes
HttpContext.Current.Response.Write(cv)
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("Content-Disposition",
"attachment;filename = test.pdf")
HttpContext.Current.Response.BinaryWrite(cv)
HttpContext.Current.Response.End()
End Sub

"Jon Paal [MSMD]" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>I may be missing your objective, but it seems that a formview, and
associated upload control, would be dealt with through an event handler
(code beside or in page) rather than a business object layer...

Mar 31 '07 #6
maybe this will help you as an example of a helper class...

http://weblibraries.sourceforge.net/...load_proj.html
"Chris" <no****@nospam.comwrote in message news:%2****************@TK2MSFTNGP02.phx.gbl...
What I mean is that I don't want to put business logic about e.g. where an object is saved in the presentation layer. If this is
something that you can't really acheive with the formview/objectdatasorce I have a work around it's not very good but I have
posted it. A cleaner solution is to bind the the stream to byte array and use that in the business layer.

My slightly hacky work around is to tell pass the business object the name of the formview and fileupload and it find it on the
page. It works but I don't like it....

<form id="form1" runat="server" enctype="multipart/form-data">
<div>
&nbsp;<asp:FormView ID="frmvwCustomer" runat="server" DataSourceID="objdsCustomer" DefaultMode="Insert" AllowPaging="True">
<InsertItemTemplate>
Name<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />
Email<asp:TextBox ID="txtemail" Text="<%# Bind('strEmail') %>" runat="server"></asp:TextBox><br />
CV<asp:FileUpload ID="CV" runat="server" /><br />
&nbsp;<asp:Button ID="Button1" runat="server" CommandName="Insert" Text="Button" />
</InsertItemTemplate>
</asp:FormView>
</div>
<asp:ObjectDataSource ID="objdsCustomer" runat="server" InsertMethod="createcustomer"
SelectMethod="getcustomer_list" TypeName="Customer">
<InsertParameters>
<asp:Parameter Name="strname" Type="String" />
<asp:Parameter Name="strEmail" Type="String" />
<asp:Parameter Name="formview" DefaultValue="frmvwCustomer" Type="String" />
<asp:Parameter Name="upload" DefaultValue="CV" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
</form>
Public Sub createcustomer(ByVal strname As String, ByVal strEmail As String, ByVal formview As String, ByVal upload As String)
Dim page As Page = HttpContext.Current.CurrentHandler
Dim frmvw As FormView = CType(page.FindControl(formview), FormView)
Dim fileup As FileUpload = CType(frmvw.FindControl(upload), FileUpload)
Dim cv() As Byte = fileup.FileBytes
HttpContext.Current.Response.Write(cv)
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename = test.pdf")
HttpContext.Current.Response.BinaryWrite(cv)
HttpContext.Current.Response.End()
End Sub

"Jon Paal [MSMD]" <Jon[ nospam ]Paal @ everywhere dot comwrote in message news:%2***************@TK2MSFTNGP04.phx.gbl...
>>I may be missing your objective, but it seems that a formview, and associated upload control, would be dealt with through an
event handler (code beside or in page) rather than a business object layer...


Mar 31 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chris | last post: by
2 posts views Thread by Islamegy® | last post: by
reply views Thread by ThePurpleCat | last post: by
reply views Thread by =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post: by
5 posts views Thread by =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post: by
reply views Thread by =?Utf-8?B?Z292ZXI=?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.