CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > visual_studio.visual_web_developer_2005_express Tags:
Item Type: NewsGroup Date Entered: 1/5/2005 3:30:42 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 3 Views: 91 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
SixString
Asp.Net User
Upload File Example ...1/5/2005 3:30:42 PM

0

Hi ;)

Does anybody has or knows of an Example on how to upload a file and save is name to the DataBase with the DetailsView Edit functionality??

I have an example that works... but it has a problem since it specify the DefaultValue of the InsertParameters ...if i move to another record and dont provide a file For that FileUpload Control and hit save ....it stores the previous value

Heres the code :


Imports System.Data.SqlClient


Imports System.Data
Partial Class images_aspx

Dim MyConn As New SqlConnection(ConfigurationSettings.ConnectionStrings("AppConnectionString1").ConnectionString)

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Private Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
DetailsView1.PageIndex = DetailsView1.PageCount
End Sub

Private Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting

Dim PictureInsert As FileUpload = CType(DetailsView1.FindControl("PictureInsert"), FileUpload)
Dim ThumbInsert As FileUpload = CType(DetailsView1.FindControl("ThumbInsert"), FileUpload)

If PictureInsert.HasFile = True Then
SqlDataSource1.InsertParameters("Picture").DefaultValue = PictureInsert.FileName
End If

If ThumbInsert.HasFile = True Then
SqlDataSource1.InsertParameters("Thumb").DefaultValue = ThumbInsert.FileName
End If


End Sub

Private Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating


Dim PictureUpdate As FileUpload = CType(DetailsView1.FindControl("PictureUpdate"), FileUpload)
Dim ThumbUpdate As FileUpload = CType(DetailsView1.FindControl("ThumbUpdate"), FileUpload)

If PictureUpdate.HasFile = True Then
SqlDataSource1.UpdateParameters("Picture").DefaultValue = PictureUpdate.FileName
End If

If ThumbUpdate.HasFile = True Then
SqlDataSource1.UpdateParameters("Thumb").DefaultValue = ThumbUpdate.FileName
End If

End Sub

End Class





<%@ Page Language="VB" AutoEventWireup="false" CompileWith="images.aspx.vb" ClassName="images_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Setup</title>
<link href="StyleSheet.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form runat=server>
<div>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT * FROM [Pictures]"
ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>" DeleteCommand="DELETE FROM [Pictures] WHERE [Id] = @original_Id" InsertCommand="INSERT INTO [Pictures] ([Name], [Picture], [Thumb]) VALUES (@Name, @Picture, @Thumb)" UpdateCommand="UPDATE [Pictures] SET [Name] = @Name, [Picture] = @Picture, [Thumb] = @Thumb WHERE [Id] = @original_Id" ConflictDetection="CompareAllValues">
<DeleteParameters>
<asp:Parameter Type="Int32" Name="Id"></asp:Parameter>
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Type="String" Name="Name"></asp:Parameter>
<asp:Parameter Type="String" Name="Picture"></asp:Parameter>
<asp:Parameter Type="String" Name="Thumb"></asp:Parameter>
<asp:Parameter Type="Int32" Name="Id"></asp:Parameter>
</UpdateParameters>
<InsertParameters>
<asp:Parameter Type="String" Name="Name"></asp:Parameter>
<asp:Parameter Type="String" Name="Picture"></asp:Parameter>
<asp:Parameter Type="String" Name="Thumb"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource>&nbsp;</div>
<asp:DetailsView ID="DetailsView1" Runat="server" DataSourceID="SqlDataSource1" AutoGenerateRows="False"
DataKeyNames="Id" AllowPaging="True">
<PagerSettings Position="TopAndBottom" NextPageText="" NextPageImageUrl="~/images/next.png"
FirstPageText="" LastPageImageUrl="~/images/last.png" LastPageText="" PreviousPageText=""
PreviousPageImageUrl="~/images/previous.png" FirstPageImageUrl="~/images/first.png"
Mode="NextPreviousFirstLast" PageButtonCount="5"></PagerSettings>
<Fields>
<asp:BoundField ReadOnly="True" HeaderText="Id" InsertVisible="False" DataField="Id"
SortExpression="Id">
<ItemStyle CssClass="Label" HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
<HeaderStyle CssClass="TitleLabel" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name">
<ItemStyle CssClass="Label" HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<HeaderStyle CssClass="TitleLabel" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField SortExpression="Picture" HeaderText="Picture"><EditItemTemplate>
<asp:FileUpload ID="PictureUpdate" Runat="server" />
</EditItemTemplate>
<ItemStyle CssClass="Label" HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<table align="center"><tr>
<td style="width: 100px">
<asp:Label ID="Label1" Runat="server" Text='<%# Eval("Picture") %>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:HyperLink ID="HyperLink1" Runat="server" ImageUrl='<%# Eval("Picture") %>' NavigateUrl='<%# "~/default.aspx?Id=" &amp;amp; Eval("Id") &amp;amp; "&amp;amp;Name=" + Eval("Name") %>' Text='<%# Eval("Name") %>'></asp:HyperLink>
</td>
</tr></table>
</ItemTemplate>
<InsertItemTemplate>
<asp:FileUpload ID="PictureInsert" Runat="server" />
</InsertItemTemplate>
<HeaderStyle CssClass="TitleLabel" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField SortExpression="Thumb" HeaderText="Thumb"><EditItemTemplate>
<asp:FileUpload ID="ThumbUpdate" Runat="server" />
</EditItemTemplate>
<ItemStyle CssClass="Label" HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<div style="text-align: center">
<table><tr>
<td style="width: 100px">
<asp:Label ID="Label2" Runat="server" Text='<%# Eval("Thumb") %>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:HyperLink ID="HyperLink2" Runat="server" ImageUrl='<%# Eval("Thumb") %>' Text='<%# Eval("Name") %>'></asp:HyperLink>
</td>
</tr></table>
</div>
</ItemTemplate>
<InsertItemTemplate>
<asp:FileUpload ID="ThumbInsert" Runat="server" />
</InsertItemTemplate>
<HeaderStyle CssClass="TitleLabel" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" ShowEditButton="True" NewImageUrl="~/images/new.gif" ButtonType="Image" EditImageUrl="~/images/edit.gif" EditText="Edit" UpdateImageUrl="~/images/edit.gif" CancelText="Cancel" NewText="New" InsertText="" CancelImageUrl="~/images/drop.gif" UpdateText="Save" DeleteText=""></asp:CommandField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>



Im kinda new to this so if anyone can help would be Great :)

Cheers
Fredrik N
Asp.Net User
Re: Upload File Example ...1/5/2005 3:52:16 PM

0

Because of security reasons you can set the FileNmae of the Upload control, so you have to handle this programmatically. You could for example use a hidden filed to store the filename that is already added to the data source. If the FileName is empty, you get the value from the hidden field and set it as a value to the parameter.
/Fredrik Norm?n NSQUARED2
Microsoft MVP, MCSD, MCAD, MCT

Cornerstone

My Blog, ASP.Net 2.0 etc
SixString
Asp.Net User
Re: Upload File Example ...1/5/2005 5:22:06 PM

0

Thaks a lot Fredrik :)

That does the Trick ....another thing ... the ImageField will not have the ImageData Mode in Beta2 ???

Cheers
Fredrik N
Asp.Net User
Re: Upload File Example ...1/5/2005 6:17:56 PM

0

No, the ImageData is removed. The ImageField could only display an image based on an URL.
/Fredrik Norm?n NSQUARED2
Microsoft MVP, MCSD, MCAD, MCT

Cornerstone

My Blog, ASP.Net 2.0 etc
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Jakarta Struts Cookbook Authors: Bill Siggelkow, Pages: 507, Published: 2005
Beginning PHP and MySQL 5: From Novice to Professional Authors: W. Jason Gilmore, Pages: 913, Published: 2006
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
Twisted Network Programming Essentials: Event-driven Programming with Python Authors: Abe Fettig, Glyph Lefkowitz, Pages: 213, Published: 2006
Beginning PHP and PostgreSQL 8: From Novice to Professional Authors: W. Jason Gilmore, Robert H. Treat, Pages: 857, Published: 2006
The Web Testing Companion: The Insider's Guide to Efficient and Effective Tests Authors: Lydia Ash, Pages: 554, Published: 2003
PHP and MySQL by Example Authors: Ellie Quigley, Marko Gargenta, Pages: 878, Published: 2006
PHP Black Book: Comprehensive Problem Solver Authors: Peter Moulding, Pages: 845, Published: 2001
Java Servlet and JSP Cookbook: Practical Solutions to Real-world Problems Authors: Bruce W. Perry, Pages: 723, Published: 2004
PHP by Example: By Example Authors: Toby Butzon, Pages: 408, Published: 2002

Web:
Sample File Upload Form Jul 31, 1996 ... Sample File Upload Form. NOTE: This script is not operative on this ... The file upload form looks just like any other form except that: ...
JSP Example: File Uploading This example uses the framework to upload files. The multipart form data is parsed and mapped to JavaBean objects automatically.
File upload JSP/Servlet example, multipart/form-data, JDBC ... Java API for Servlet/JSP programming. Java Swing GUI builder by XML.
PHP Tutorial - File Upload Learn the basics of uploading files with PHP by reading Tizag.com's PHP File Upload lesson.
9 Flex File Upload Examples Visited This is another good Flex file upload example that handles both client and server ends. The server side is ColdFusion, which is very familiar to lots of ...
www.dhtmlgoodies.com :: View topic - upload file example Does anyone have an upload file example? We are using asp but if you have php we can figure it out as well. Upload with progress bar would ...
PHP Tutorial: Uploading Files The first associative index we need is to indicate which file we are talking about -- in our example here we only included one upload file, but our form ...
Struts File Upload Example Struts File Upload Example. In this tutorial you will learn how to use Struts to write program to upload files. The interface org.apache.struts.upload. ...
PHP File Upload For example, when viewed in a browser, there will be a browse-button next to the input field. Note: Allowing users to upload files is a big security risk. ...
Java Servlet / JSP File Upload: Example JSP File Upload Script Example JSP File Upload Script. Preferences - Do not show ads. Below shows a JSP file upload script that is used to print out the name-value pair received ...

Videos:
Perl Tutorial 61 - CGI.pm - File Uploads via Upload Form http://www.ScriptSocket.com/ Part 61 of the Perl Tutorial explores the CGI.pm module to create an upload form and upload files to your server.
PSP Tutorial - How to Upload a Video File onto My PSP This video demostrates, in words, sound and images how to convert and upload videos onto your PSP. Total Video Converter (trial)- http://www ...
Tutorial Moodle How to Upload Files to Assignments and Forums Moodle: How to Upload Files to Forums and Assignments Dennis Daniels Uploading Is Easy Browse Biggest problem is finding the document ...
Free Website, Part2: Easy File Upload Example http://www.blootow.com Free Website, Part2: Easy File Upload Example, http://www.new4music.com http://www.myspace.com/runnerrunnermusic
PHP Forms Generation and Validation tutorial Tutorial presentation of the PHP Forms Generation and Validation class Please watch this video instead in this page. Since the video is very ...
Browse and Upload Files Using Flash and AS3 - CS3 Tutorial Download Free Flash CS3 fla file here http://www.developphp.com/Flash_tuts/AS3_File_Upload.php
NCAA Football 09 PS3 Roster Upload Tutorial Here it is guys. I just changed the 08 to an 09 since the process is identical for this year as well. UPDATE DEC 1: Here is a link for post ...
PHP file upload File Upload tutorial by [email protected] Larger version of the tutorial and others on site.
MyBloop Upload Tutorial 3 min. tutorial of how to upload files with the Flash uploader and the new Blooploader desktop application.












system.web.profile.defaultprofile' has multiple definitions with identical signatures

visual web developer express 2005 and visual studio .net 2005

"not declared error" when i copy vb code from one page to another

intelisense not working in code behind

bug?

where to get missing project templates?

visual web developer - web application administrator - live site

vs2005 problem

pop-up message window

generating create scripts?

favourite links

debugging client script with vwd 2005

cannot view default.aspx in design mode

prebuild web pages

bind method

events for textbox

add new project

data store problem

some questions

building website

vista home and visual web developer 2005 express

view in browser

webcontrol like datepiker for vwd2005?

add codebehind pages

why do i have no bin folder?

me've a big questions in using visual web developer 2005 express and .net framework 2.0

can't really design a table

showing modal dialog box

where is my dll?

no (vwd gui) way to add a new provider in feb ctp

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT