473,508 Members | 2,398 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.PostedFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw)
Try
inputFile.PostedFile.SaveAs(destination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execption Message: " & exc.Message.ToString() &
"<br />")
r.Write("Execption Source: " & exc.Source.ToString())
r.Write("Execption Stack: " & exc.StackTrace.ToString())
success = False
End Try
Return success
End If
End Function
Nov 17 '05 #1
3 3269
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****************@TK2MSFTNGP12.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.PostedFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw)
Try
inputFile.PostedFile.SaveAs(destination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execption Message: " & exc.Message.ToString() & "<br />")
r.Write("Execption Source: " & exc.Source.ToString())
r.Write("Execption 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.NullReferenceException: 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.PostedFile 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**************@TK2MSFTNGP10.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****************@TK2MSFTNGP12.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.PostedFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw)
Try
inputFile.PostedFile.SaveAs(destination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execption Message: " & exc.Message.ToString()
&
"<br />")
r.Write("Execption Source: " &

exc.Source.ToString()) r.Write("Execption 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**************@TK2MSFTNGP12.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.NullReferenceException: 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.PostedFile 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**************@TK2MSFTNGP10.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****************@TK2MSFTNGP12.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.PostedFile Is Nothing) Then
Dim tw As TextWriter
Dim r As HttpResponse = New HttpResponse(tw)
Try
inputFile.PostedFile.SaveAs(destination)
success = True
Catch exc As Exception
' r is a reference to httpResponse Object
r.Write("Execption Message: " & exc.Message.ToString()
&
"<br />")
r.Write("Execption Source: " &

exc.Source.ToString()) r.Write("Execption 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
3980
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...
6
2813
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...
5
7815
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...
5
5450
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...
0
2180
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...
221
366982
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...
2
2312
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...
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...
3
5158
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
7231
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
7336
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
7405
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
7504
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...
1
5059
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...
0
3214
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
1568
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 ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
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...

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.