473,738 Members | 7,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileUpload control and formView Inserting Event

Dear All,

Please find below an Inserting Event code expected to trigger just
before the insert event of a FormView control. Everything works just
fine but the event throws an exception that the parameter Filename is
null. As you can see in the code that I have tried to update the
UploadedFileNam e textbox which is bound to the Filename column of the
database connection. During execution of the command, it is not found
to update the UploadedFileNam e textbox's text property even though I
have explicitly declared the textbox variable "MyUploadedFile Name".
Please help me out.

Protected Sub FormView1_ItemI nserting(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Form ViewInsertEvent Args) Handles
FormView1.ItemI nserting

Dim MyUploadedFileN ame As TextBox =
FormView1.FindC ontrol("Uploade dFileName")

Dim path As String = Server.MapPath( "~/UploadedImages/")
Dim fileOK As Boolean = False
If FileUpload1.Has File Then
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(Fi leUpload1.FileN ame).ToLower()
Dim allowedExtensio ns As String() = _
{".jpg", ".jpeg", ".png", ".gif"}
For i As Integer = 0 To allowedExtensio ns.Length - 1
If fileExtension = allowedExtensio ns(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
FileUpload1.Pos tedFile.SaveAs( path & _
FileUpload1.Fil eName)
MyUploadedFileN ame.Text =
FileUpload1.Fil eName.ToString( )
Catch ex As Exception
Label1.Text = "File could not be uploaded."
End Try
Else
Label1.Text = "Cannot accept files of this type."
End If
End If
End If
End Sub

May 14 '07 #1
0 2162

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

Similar topics

1
2587
by: yuchang | last post by:
Hi, Using the FormView control is very efficient. But I want to do some action,like showing a success message or redirect to another page, after inserting, updating and deleting. How do I get these message?
0
1104
by: Chris | last post by:
I want to display a formview based on an objectdatasource. One of the things on the formview will be a link to a pdf. When I go into the edit template I would like a fileupload to display, which can be used to upload a new pdf. I would like my object to be as reusable as possible. Can anyone recommend a way of referencing the fileupload control in as flexible way as possible. The thing I would like to avoid is using my object on several...
2
2953
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 & onItemUpdating but no luck.. FindControl() didn't work and can't find my fileUpload control.. any help plzzzzzzzzzz?? I just upgraded to .net 2 and find to much problems with FindControl() in template controls.. and also i face too many problems...
2
2772
by: Kelly | last post by:
I'm fairly new to ASP.NET2, but I have an ASP 3.0 background, and I've been experimenting with the DataSource and FormView widgets. I wound up having some questions along the way which I hope you all can address to help me understand events with these better. I've been reading up on inserted/inserting also deleted/deleting, but where is it better to run call those events from via formview or datasource? Also, I have been trying to...
6
7341
by: Chris | last post by:
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...
0
936
by: RosH | last post by:
Dear All, Please find below an Inserting Event code expected to trigger just before the insert event of a FormView control. Everything works just fine but the event throws an exception that the parameter Filename is null. As you can see in the code that I have tried to update the UploadedFileName textbox which is bound to the Filename column of the database connection. During execution of the command, it is not found to update the...
0
2774
by: =?Utf-8?B?Z292ZXI=?= | last post by:
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...
1
1364
by: bogdan | last post by:
Hi, I have a FormView where one of the items is a file name. All items come from a single data source. I'd like to have the file name also displayed in a FileUpload control on the same page. Ideally I'd like to have the FileUpload control embedded in a FormView so the file name appears only once on the page. Is this possible? What are the alternatives? Thanks, Bogdan
5
2767
by: =?Utf-8?B?VEQgaXMgUFNQ?= | last post by:
I have a FileUpload control within a FormView (although I tried it outside the FormView and got the same result) in the InsertTemplate. When the <Insertbutton is clicked and the Insert Command is executed the FileUpload is cleared of it's value and hence during Insert there is no file to "insert". I even tried this with a separate button that was both inside and outside the form view and not connected to the Insert Command, and still the...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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 we have to send another system

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.