473,668 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wrapper function for uploading files

Hi,

I was wondering how to go about creating a wrapper function for uploading
files to the server? I have made an attempt on my own without success. I
don't get any exceptions from the function but It doens't upload the file
either. Any help is appreciated.

Brian

'************** *******
'** Code Snip
'************** *******
Function HtmlFileUpload( ByVal inputFile As HtmlInputFile, _
ByVal destination As String) As Boolean
'
Dim contentLength As Integer
inputFile = New HtmlInputFile()
Dim success As Boolean = False
Dim contentType As String
If (Not inputFile.Poste dFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw )
Try
inputFile.Poste dFile.SaveAs(de stination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execpt ion Message: " & exc.Message.ToS tring() &
"<br />")
r.Write("Execpt ion Source: " & exc.Source.ToSt ring())
r.Write("Execpt ion Stack: " & exc.StackTrace. ToString())
success = False
End Try
Return success
End If
End Function
Nov 17 '05 #1
3 3276
Your method has a parameter called "inputFile" which I assume is the
uploaded file. Then, you assign it to a "New InputFile()" which initializes
to an empty HtmlInputFile. Take out that line (inputFile = New
HtmlInputFile() ").

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

"Brian Pittman" <bp******@nlta. nf.ca> wrote in message
news:eg******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I was wondering how to go about creating a wrapper function for uploading
files to the server? I have made an attempt on my own without success. I
don't get any exceptions from the function but It doens't upload the file
either. Any help is appreciated.

Brian

'************** *******
'** Code Snip
'************** *******
Function HtmlFileUpload( ByVal inputFile As HtmlInputFile, _
ByVal destination As String) As Boolean
'
Dim contentLength As Integer
inputFile = New HtmlInputFile()
Dim success As Boolean = False
Dim contentType As String
If (Not inputFile.Poste dFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw )
Try
inputFile.Poste dFile.SaveAs(de stination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execpt ion Message: " & exc.Message.ToS tring() & "<br />")
r.Write("Execpt ion Source: " & exc.Source.ToSt ring())
r.Write("Execpt ion Stack: " & exc.StackTrace. ToString()) success = False
End Try
Return success
End If
End Function

Nov 17 '05 #2
Hey Kevin,

Thanks for the quick response. I took out the line you specified but I
threw an exception when I did. Here is the exception

Exception Details: System.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

Line 30: Dim success As Boolean = False
Line 31: Dim contentType As String
Line 32: If (Not inputFile.Poste dFile Is Nothing) Then
Line 33: Dim tw As TextWriter
Line 34: Dim r As HttpResponse = New HttpResponse(tw )
how do I fix this? Thanks again

Brian

"Kevin Spencer" <ke***@takempis .com> wrote in message
news:eu******** ******@TK2MSFTN GP10.phx.gbl...
Your method has a parameter called "inputFile" which I assume is the
uploaded file. Then, you assign it to a "New InputFile()" which initializes to an empty HtmlInputFile. Take out that line (inputFile = New
HtmlInputFile() ").

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

"Brian Pittman" <bp******@nlta. nf.ca> wrote in message
news:eg******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I was wondering how to go about creating a wrapper function for uploading files to the server? I have made an attempt on my own without success. I don't get any exceptions from the function but It doens't upload the file either. Any help is appreciated.

Brian

'************** *******
'** Code Snip
'************** *******
Function HtmlFileUpload( ByVal inputFile As HtmlInputFile, _
ByVal destination As String) As Boolean
'
Dim contentLength As Integer
inputFile = New HtmlInputFile()
Dim success As Boolean = False
Dim contentType As String
If (Not inputFile.Poste dFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw )
Try
inputFile.Poste dFile.SaveAs(de stination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execpt ion Message: " & exc.Message.ToS tring()
&
"<br />")
r.Write("Execpt ion Source: " &

exc.Source.ToSt ring()) r.Write("Execpt ion Stack: " &

exc.StackTrace. ToString())
success = False
End Try
Return success
End If
End Function


Nov 17 '05 #3
Let me see if I can brief you on the basic principle you seem to continually
run up against here:

A variable is not a class. It is a REFERENCE to a class. In other words, if
you declare a variable such as your "tw" variable, all you've done is to
declare a "container" for the data type that it represents (in this case, a
TextWriter). When you first declare ("Dim") the variable, it doesn't refer
to anything. It refers to nothing. You have to ASSIGN the variable to get it
to refer to an actual class. Therefore, in the code which you just posted,
you declare a variable named "tw" as a TextWriter, but assign nothing to it.
At this point it is not referencing an instance of an object, it is
referencing Nothing. The very next thing you did was to pass it to the
constructor method of a HttpResponse. In other words, you passed NOTHING to
the constructor method. NOTHING is not an instance of an object; it is
Nothing.

There is also a difference between declaring and instantiating (or
assigning) an object variable. Consider the following:

Dim x As Object ' x = Nothing
Dim x As Object = New Object() ' x = a new instance of the Object class
Dim x As New Object() ' x = a new instance of the Object class (the type is
inferred from the initialization)
Dim x As Object = SomeObject ' x is assigned to represent or point to
SomeObject, which would be an instance of an Object

So, while .Net allows you to combine some of these operations in a single
statement, and infer a thing or 2, you need to be aware that the single
statement is actually performing several things with one statement. In order
to use variables in a .Net app, you need to do the following:

1. Declare ("Dim") the variable (with Option Strict turned ON [recommended],
you must declare the type as well).
2. Assign the variable to an instance of an object. There are 2 ways to do
this:
a. Instantiate a New instance of an object and assign that to the
variable
b. Assign an existing object to the variable

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
"Brian Pittman" <bp******@nlta. nf.ca> wrote in message
news:e0******** ******@TK2MSFTN GP12.phx.gbl...
Hey Kevin,

Thanks for the quick response. I took out the line you specified but I
threw an exception when I did. Here is the exception

Exception Details: System.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

Line 30: Dim success As Boolean = False
Line 31: Dim contentType As String
Line 32: If (Not inputFile.Poste dFile Is Nothing) Then
Line 33: Dim tw As TextWriter
Line 34: Dim r As HttpResponse = New HttpResponse(tw )
how do I fix this? Thanks again

Brian

"Kevin Spencer" <ke***@takempis .com> wrote in message
news:eu******** ******@TK2MSFTN GP10.phx.gbl...
Your method has a parameter called "inputFile" which I assume is the
uploaded file. Then, you assign it to a "New InputFile()" which initializes
to an empty HtmlInputFile. Take out that line (inputFile = New
HtmlInputFile() ").

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

"Brian Pittman" <bp******@nlta. nf.ca> wrote in message
news:eg******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I was wondering how to go about creating a wrapper function for uploading files to the server? I have made an attempt on my own without
success. I don't get any exceptions from the function but It doens't upload the file either. Any help is appreciated.

Brian

'************** *******
'** Code Snip
'************** *******
Function HtmlFileUpload( ByVal inputFile As HtmlInputFile, _
ByVal destination As String) As Boolean
'
Dim contentLength As Integer
inputFile = New HtmlInputFile()
Dim success As Boolean = False
Dim contentType As String
If (Not inputFile.Poste dFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw )
Try
inputFile.Poste dFile.SaveAs(de stination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execpt ion Message: " & exc.Message.ToS tring()
&
"<br />")
r.Write("Execpt ion Source: " &

exc.Source.ToSt ring()) r.Write("Execpt ion Stack: " &

exc.StackTrace. ToString())
success = False
End Try
Return success
End If
End Function



Nov 17 '05 #4

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

Similar topics

7
3996
by: lion | last post by:
I get these errors when uploading images via a web page: (the page still uploads the images but reports these errors?) Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) : failed to create stream: No error in D:\webspace\me.co.uk\wwwroot\test\Live.php on line 105 Warning: Wrong parameter count for filesize() in D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109
6
2823
by: Chamomile | last post by:
can anyone point me to some straightforward information on file uploading without using an html form? That is, direcly from within a php script. if I know the local path etc. to a particular requested file how can I send it directly to a location on a remote webserver following a request from the remote server? The motivation is that I have a large number of image files that are
5
7830
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of files via FTP. I'm using ftplib to do it, and for each file I'm using transfercmd("STOR " + myfile) to get the socket, then uploading 4096 bytes at a time and providing status updates via a GUI interface. Finally, I close the socket, set it to...
5
5460
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and replacing it with a button of my own background color and text. The file paths I'd like displayed in a textarea and then the files uploaded at once.
0
2203
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted file using SHA256 (I have taken the code from: http://www.vbforums.com/showthread.php?s=&threadid=232284)
221
367416
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
2
2333
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
jodleren escribió: I haven't found the PHP manual page where such feature is documented but a few tests have shown that this behaviour changes depending on the charset parameter of the "Content-Type" HTTP header; even if I don't set an actual HTTP header and I just use a <metatag: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> With a packet sniffer I've determined that it's not the browser who
1
726
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried uploading the files on the server and experienced the same issues as I get on any other computer. Thanks in advance for your help. Dan
3
5175
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
8462
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
8802
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...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
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
7405
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...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.