Trying to create a FIle Upload page using vb.net

Can someone give me some advise on what I may be doing wrong in creating the file upload below. I'm trying to create a file upload page for a site that I'm developing, and whenever I click the  "Upload Image Button" nothing happens....the image that I'm trying to upload doesn't appear as expected.

I have included the VB.NET code below.

Thanks

 code for uploadfile.aspx.vb

Public Class uploadfile1

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink

Protected WithEvents lblTitle As System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents txtUsername As System.Web.UI.HtmlControls.HtmlInputText

Protected WithEvents txtPassword As System.Web.UI.HtmlControls.HtmlInputText

Protected WithEvents lblUsername As System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents lblPassword As System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents btnSubmit As System.Web.UI.HtmlControls.HtmlInputButton

Protected WithEvents txtFileName As System.Web.UI.HtmlControls.HtmlInputText

Protected WithEvents btnImage As System.Web.UI.HtmlControls.HtmlInputButton

Protected WithEvents lblFilename As System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents btnReUpload As System.Web.UI.HtmlControls.HtmlInputButton

Protected WithEvents lblMessage As System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents uploadFilePath As System.Web.UI.HtmlControls.HtmlInputFile

'NOTE: The following placeholder declaration is required by the Web Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

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

'Put user code to initialize the page here

ShowUserAuthenticationControls()

HideFileUploadControls()

End Sub

Function ShowUserAuthenticationControls()

' Show the user authentication controls

lblUsername.Visible = True

lblPassword.Visible = True

txtUsername.Visible = True

txtPassword.Visible = True

btnSubmit.Visible = True

btnReUpload.Visible = False

End Function

Function HideUserAuthenticationControls()

' Hide the user authentication controls

lblUsername.Visible = False

lblPassword.Visible = False

txtUsername.Visible = False

txtPassword.Visible = False

btnSubmit.Visible = False

btnReUpload.Visible = False

End Function

Function ShowFileUploadControls()

'Hide the user authentication controls

uploadFilePath.Visible = True

txtFileName.Visible = True

btnImage.Visible = True

lblFilename.Visible = True

lblTitle.InnerHtml = "Upload an Image"

End Function

Function HideFileUploadControls()

'Hide the user authentication controls

uploadFilePath.Visible = False

txtFileName.Visible = False

lblFilename.Visible = False

btnImage.Visible = False

HyperLink1.Visible = False

End Function

Function ResetUserAuthenticationControls()

'Reset the user authentication controls

lblTitle.InnerHtml = "Upload an Image"

txtUsername.Value = ""

txtPassword.Value = ""

End Function

Private Sub btnImage_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImage.ServerClick

If txtFileName.Value = "" Then

lblTitle.InnerHtml = "Error: You must enter a file name."

HideUserAuthenticationControls()

ShowFileUploadControls()

Return

End If

If Not (uploadFilePath.PostedFile Is Nothing) Then

Try

Dim strFilePath As String

strFilePath = System.IO.Path.GetDirectoryName(Server.MapPath("uploadfile.aspx"))

uploadFilePath.PostedFile.SaveAs((strFilePath & "/" & txtFileName.Value))

lblTitle.InnerHtml = "File uploaded successfully"

lblMessage.InnerHtml = "Your file was uploaded successfully to <br>" & _

"<b>" & strFilePath & "\" & _

txtFileName.Value & "</b><br>on the Web server."

HideFileUploadControls()

HideUserAuthenticationControls()

lblMessage.Visible = True

btnReUpload.Visible = True

HyperLink1.NavigateUrl = "http://localhost/chapter4/" & txtFileName.Value

HyperLink1.Visible = True

Catch exc As Exception

lblTitle.InnerHtml = "Error saving file"

End Try

End If

End Sub

Private Sub btnSubmit_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.ServerClick

If ((txtUsername.Value = "Course") And (txtPassword.Value = "Technology")) Then

ShowFileUploadControls()

HideUserAuthenticationControls()

Else

lblTitle.InnerHtml = "Error logging in"

Return

End If

End Sub

Private Sub btnReUpload_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReUpload.ServerClick

ResetUserAuthenticationControls()

HideUserAuthenticationControls()

ShowFileUploadControls()

txtFileName.Value = ""

btnReUpload.Visible = False

lblMessage.Visible = False

End Sub

End Class

0
ramelllamar
3/26/2007 5:53:10 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
1165 Views

Similar Articles

[PageSpeed] 56

You have not given HTML here. I guess you are not posting page as per the RFC standard. You need to use

enctype="multipart/form-data"

In form tag

I hope this helps


Everything is possible!
0
atsofttech
3/26/2007 6:12:13 AM
 Does the user  have permission to read/write in the Proposed Directory?
0
omerkamal
3/26/2007 6:30:15 AM
Reply:

Similar Artilces:

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Auto create HTML page with the upload image file inside the page VB.NET
Hello guys, I want to create automatically an html page with the image i 've uploaded before. Any help ??? Thank you in advance Hi mate, you do not need create a html page per each image you upload to the server... only build an empty aspx page (viewer.aspx???) with an asp:image control...  and call it each time you needs it, let's see: 1.- create a property named myImage in the page you upload the image (ie. source.aspx) Public ReadOnly Property myimage() As StringGetReturn "uploaded_image_name"End GetEnd Property 2.- add this tag into your asp...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

vb.net web project
Hi All, I have a situation in my web application whereby after accepting username & password from user I want to create a text file on web server and then upload it to somewhere via ftp? Any one can help me doing this please? Best Regards, Usman Why dont you have a Web Service on the server that creates the text file and then make an instance of it when someone login that is creating the file.Mikael Söderström...

Posting filepath in file upload control in .NET to the next page and uploading the file from second page
In our application (using C# .NET) there is a form with file upload options. After filling up the form details, the summary of the details need to be shown in the next page before committing the information into the database. Right now, Server.Control is used to transfer the contents to the next page and the form details are retrieved using Request.Form["control id"]. But this is not working for File upload control alone.File upload can not be done in the first page itself, as the foreign key in File upload table gets updated only in second page after confirmation. Therefore, is th...

Both C# ASPX pages and VB.NET ASPX in single VB.NET Web Applcation Template
Hi.. Is it possible to have both c# pages and VB pages in same Webapplication, what i chose is VB.NET Web application Template. With Thanks, Jaya.... I don't see why you couldn't, but for the sake of consistency I don't know why you would want to do this. When you choose a C# or VB.NET application template(I'm assuming you're using VS or WebMatrix), it simply creates a .aspx file that includes a page directive that specifies the page language. If you created a C# template but want to use VB.Net instead, you need to go from: <%@ Page Language="C#" .... to...

How to get HTML Source of web page opened by web browser using vb.net
hello friends,         i have opened an web browser in vb.net using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim nullObject As System.Object = 0 Dim str As String = "" Dim nullObjStr As System.Object = str Windows.Forms.Cursor.Current = Cursors.WaitCursor Dim i As Int16 For i = 1 To 2 AxWebBrowser1.Navigate("http://www.google.co.in/search?hl=en&q=test&meta=", True) AxWebBrowser1.Document. Next Windows.Forms.Cursor.Current = Cursors.Default End Sub  ...

File upload in chunks
So I downloaded the files from codeproject for the "upload files in chunks" application at http://www.codeproject.com/KB/XML/MTOMWebServices.aspx?df=100&forumid=250646&exp=0&select=2292508 I've adapted the c# code into vb.net and tests I run locally show it working ok.  Trouble is, the client side was written for windows application level client, not web, so I'm wondering if anyone has already got a bit of client side web coding to take an uploaded file and split it into chunks that is compatible with this web service at all? Well I use MTOM and WSE 3.0 ...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Functions in Web Pages using VB.NET
Does anyone know where to place a FUNCTION with WEB Programming using VB.NET code behind? For example, if I have 4 ASPX pages and will use the same function, where or what part of the web page can I place this function or do I need to have that function in each of the ASPX page? Unlike in a COM program using VB.NET, that function would most probably reside in the MODULE and any VB.NET form can easily call it. TIF you can put it in a class***********************Dinakar NethiLife is short. Enjoy it.*********************** Thanks....

Creating an Excel file using VB.Net
Just after some help to create an Excel file using VB.Net please. I've had a bit of a hunt around but can't find an exact example of code that I'm after. I'm new to .Net and VB.Net and wanted to create and save records to an EXCEL file. I can translate from C# if need be. Thanks for any help. Hi Amelia99, welcome to the forums. Which version of Excell do you want to use? The latest version (2003) has xml possibilities and you can download a free SDK at the microsoft site that makes it quite easy to use with vs.net 2003. It makes new project templates and one of them is for ex...

Create Web Parts using VB.net
First of all i've never created any web part so i need a sample code that help me to know the process (step by step) to create web parts using VB.net Take a look at this post on my blog, the code example exists only in C#, but it will give you the basic understanding./Fredrik Normén - fredrikn @ twitterMicrosoft MVP, MCSD, MCAD, MCTASPInsidersMy Blog...

How to use the Streams in VB.NET for uploading the file
hi friends, I want to upload an Excel file(very large 100,000 records) to the webserver using Vb.NET My code (given down) works well when i upload the file to the local directory. If I upload to the webserver, as the file size is large i want to make use of streams and upload the file. Please help me .. How to use the Streams in VB.NET for uploading the file Thanks in advanceProtected Sub btnUploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUploadButton.Click FileName.InnerHtml = FileField.PostedFile.FileName FileContent.I...

Creating a web form in VB.NET 2003
I apologise if this has been asked a thousand times.  Firstly, I am using VB.NET 2003 (v7.1.3088) and .NET Framework 1.1.4322  SP1 on WinXP Professional SP2 platform with all security and critical updates in place.My background: good old FoxPro, VB6 and VBA under Access (yuk!)I am playing about with a test project before hopefully upgrading to VB.NET 2005 and i am having a fundamental problem with web forms for a ASP.NET web application.  Whenever I copy and paste an object (text box, label, etc) VB.NET pastes the object back onto the form apparently correctly.  After up...

Web resources about - Trying to create a FIle Upload page using vb.net - asp.net.web-forms

Full Episode: GMA 11/21/15: Brussels on High Alert
What Security Boosts Thanksgiving Travelers Should Expect; Major Storm Hits Midwest

Debate Rages On Syrian Refugees: Are The Fears Of U.S. Citizens Unfounded?
The debate rages on Syrian refugees and whether they should be allowed into the United States, in light of the Paris attacks.To date, 31 states ...

Kim Kardashian Divorce: Kim Spotted Without Wedding Ring As Reports Of Trouble With Kanye West Increase ...
Kim Kardashian is facing divorce rumors after the very pregnant reality star was spotted without a wedding ring, all amid increasing rumors of ...

Facebook billionaire Zuckerberg to take two month's paternity leave
The social media network has not named an interim chief executive.

Two Australian tourists, four Britons killed in helicopter crash in New Zealand, police believe
Two Australian and four British tourists are killed in a helicopter crash in Fox Glacier on the west coast of New Zealand's South Island, New ...

Man Arrested For Allegedly Wielding Samurai Sword At Apple Store
A man in New York City was arrested on Friday after police say he terrified shoppers by swinging a samurai sword around an Apple store. Footage ...

Chipotle Is Still Serving Burritos Laced With New Secret Ingredient: E. Coli
The country’s favorite burrito chain is at it yet again — serving their signature carnitas with a side of diarrhea. Read more...

French police release seven people picked up during raid last week
By Gregory Blachier PARIS (Reuters) - French police have released seven of the eight people rounded up when they raided a flat last Wednesday ...

‘Star Wars: The Force Awakens’ Actor Shuts Down Controversial Casting Decisions
Star Wars: The Force Awakens had fans in an uproar about the movie’s controversial casting decision, but a new actor to the franchise shut down ...

Saturday's Best Deals: Early Black Friday Sales, Your Favorite Headphones, and More
Here are the best of today’s deals. Get every great deal every day on Kinja Deals , follow us on Facebook and Twitter to never miss a deal, join ...

Resources last updated: 11/21/2015 9:32:10 PM