473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

FormView Inserting event with FileUploader control

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 UploadedFileName textbox's text property even though I
have explicitly declared the textbox variable "MyUploadedFileName".
Please help me out.

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting

Dim MyUploadedFileName As TextBox =
FormView1.FindControl("UploadedFileName")

Dim path As String = Server.MapPath("~/UploadedImages/")
Dim fileOK As Boolean = False
If FileUpload1.HasFile Then
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions As String() = _
{".jpg", ".jpeg", ".png", ".gif"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
FileUpload1.PostedFile.SaveAs(path & _
FileUpload1.FileName)
MyUploadedFileName.Text =
FileUpload1.FileName.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 21 '07 #1
0 923

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

Similar topics

2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
1
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...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
2
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...
4
by: J055 | last post by:
Hi I have 2 update buttons in my FormView ('Apply' and 'OK'). I want both buttons to update the data source but the 'OK' button should redirect afterwards. I can see which button is clicked...
0
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have...
6
by: AG | last post by:
ASP.NET 2.0 aspx page with a FormView bound to an ObjectDataSource to view, add and edit records. Can anyone point me to a sample of how to retain the user entered control values when an insert...
0
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...
0
by: =?Utf-8?B?UmJydA==?= | last post by:
I have a custom FormView control which I build in code at run time in the page pre-init event. When the user clicks a linkbutton control elsewhere on the page, I change the mode of the formview to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...

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.