Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Formview FileUpload and ObjectDataSource (http://www.velocityreviews.com/forums/t495419-formview-fileupload-and-objectdatasource.html)

Chris 03-31-2007 04:58 PM

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



Jon Paal [MSMD] 03-31-2007 05:46 PM

Re: Formview FileUpload and ObjectDataSource
 
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" <nospam@nospam.com> wrote in message news:uKpbuX7cHHA.1508@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
>
>




Chris 03-31-2007 07:08 PM

Re: Formview FileUpload and ObjectDataSource
 
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 com> wrote in message
news:eUJPEy7cHHA.4720@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" <nospam@nospam.com> wrote in message
> news:uKpbuX7cHHA.1508@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
>>
>>

>
>




Jon Paal [MSMD] 03-31-2007 07:21 PM

Re: Formview FileUpload and ObjectDataSource
 
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...




Chris 03-31-2007 09:27 PM

Re: Formview FileUpload and ObjectDataSource
 
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 com> wrote in message
news:%23wOPSn8cHHA.984@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...
>
>
>




Jon Paal [MSMD] 03-31-2007 09:39 PM

Re: Formview FileUpload and ObjectDataSource
 
maybe this will help you as an example of a helper class...

http://weblibraries.sourceforge.net/...load_proj.html


"Chris" <nospam@nospam.com> wrote in message news:%23qmZOu9cHHA.2268@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 com> wrote in message news:%23wOPSn8cHHA.984@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...
>>
>>
>>

>
>





All times are GMT. The time now is 05:59 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.