473,473 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fileupload Handling on DetailsView_RowInserting

If my code will run into the filesize-limit condition, the INSERT-statement
will be executed.

is there a way to avoid that?

Protected Sub DetailsView1_RowInserting(ByVal sender As Object, ByVal e
As DetailsViewInsertEventArgs)
Dim FileUpload As FileUpload = DetailsView1.FindControl("Bild")
If InStr(UCase(FileUpload.FileName), ".JPG") = 0 Then
txtInfo.InnerHtml = "Bitte whlen Sie ein Bild im Format .JPG"
Return
End If
If FileUpload.PostedFile.ContentLength 1000000 Then
txtInfo.InnerHtml = "Das Limit fr die Dateigrsse betrgt 1 MB"
Return
End If
If FileUpload.HasFile = True Then
'write original
Dim strFileName As String = FileUpload.FileName.ToString
Dim serverPath As String = Server.MapPath("Upload/")
Dim uploadPath As String = "../Upload/"
Dim fileToUpload As String =
FileUpload.PostedFile.FileName.ToString
Dim fileExtension As String =
System.IO.Path.GetExtension(FileUpload.FileName)
Dim fileNameOnServer As String = strFileName +
Guid.NewGuid().ToString().Substring(0, 33) + fileExtension
FileUpload.SaveAs(System.IO.Path.Combine(Server.Ma pPath("Original/"),
fileNameOnServer))

Dim path As String = Server.MapPath("Original/" &
fileNameOnServer)
'write thumbnail
CreateImage(path, Server.MapPath(fileNameOnServer))
'write image
CreateThumbnail(path, Server.MapPath("Thumbs/" &
fileNameOnServer))

txtInfo.InnerHtml = "Das Angebot wurde erfolgreich gespeichert"
SqlDataSource1.InsertParameters("Bild").DefaultVal ue =
fileNameOnServer

'delete original
Dim xfile1 As String =
"C:\Inetpub\wwwroot\ticketshop\TicketModule\BACKEN D\Original\" +
fileNameOnServer
File.Delete(xfile1)
End If
End Sub
thx,
christian
Nov 16 '06 #1
0 1305

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Islamegy® | last post by:
I'm use FormView for editing a photo gallery... I add FileUpload control to upload images to the Gallery. I'm binding my Formview to objectdatasource i tried upload images onItemInserting &...
1
by: Marko Vuksanovic | last post by:
I am trying to implement an upload progress indicator using atlas, using the following workaround: http://forums.asp.net/thread/1321664.aspx This is the code in FileUpload.apsx file is as...
12
by: Phil Z. | last post by:
After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot access a closed file" errors when uploading. I found a number of post on the subject and have since moved from using an...
4
by: Dave | last post by:
If you had a FileUpload control inside of a FormView...how would you use FindControl to access the FileUpload properties? Let me just say that...
3
by: rn5a | last post by:
The ASPX FileUpload control displays a TextBox along with a 'Browse...' Button. Setting the different properties of this control just reflects the changes in the TextBox but not the Button. For...
1
by: nicknack | last post by:
Hello. I would like to give my user the option to browse his files (like the simple fileUpload control do) and after selecting the file (and when the fileUpload control hold in his text box the...
5
by: =?Utf-8?B?QmVydA==?= | last post by:
Hi How can you set the filename property in the asp:fileupload control? How can you persist the value of the chosen filename between postbacks? thanks B
4
by: Mukesh | last post by:
i have coded like this <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server"> <asp:FileUpload ID="fupLogo" runat="server"...
2
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have a gridview with 2 columns. One column is a BoundColumn to a part number (string). One column is an ItemTemplate with a FileUpload control. There can be multiple rows (i.e. part numbers)...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.