473,403 Members | 2,270 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,403 software developers and data experts.

HTMLInputFile (Posted) file: Object reference not set Error

Dear Readers,

I am trying to take image files and store them in SQL server. as a 1st
step, I am trying to read them from a directory on the network.

in the declaration section (below the class declaration) I have:

protected System.Web.UI.HtmlControls.HtmlInputFile ImageFile;

inside the function button_click: I have

ImageFile = new HtmlInputFile();

string strFileName = "";
strFileName= ImageFile.PostedFile.FileName;

on exectuing the "strFileName = Image..." statement, it gives the
following error:
**********************************
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

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

Source Error:

Line 80:
Line 81: string strFileName = "";
Line 82: strFileName= ImageFile.PostedFile.FileName;
Line 83: string strFilePath = Path.GetFileName(strFileName);
*******************************
any help will be appreciated.

thanks and regards
Ravi.

Nov 19 '05 #1
1 2471
An HtmlInputFile Control is a UI element that provides a form field for
uploading files from a browser. You have no business using an HtmlInputFile
if you're trying to read files from the file system. Use System.IO classes
instead.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

<mr***********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Dear Readers,

I am trying to take image files and store them in SQL server. as a 1st
step, I am trying to read them from a directory on the network.

in the declaration section (below the class declaration) I have:

protected System.Web.UI.HtmlControls.HtmlInputFile ImageFile;

inside the function button_click: I have

ImageFile = new HtmlInputFile();

string strFileName = "";
strFileName= ImageFile.PostedFile.FileName;

on exectuing the "strFileName = Image..." statement, it gives the
following error:
**********************************
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

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

Source Error:

Line 80:
Line 81: string strFileName = "";
Line 82: strFileName= ImageFile.PostedFile.FileName;
Line 83: string strFilePath = Path.GetFileName(strFileName);
*******************************
any help will be appreciated.

thanks and regards
Ravi.

Nov 19 '05 #2

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

Similar topics

0
by: Viktor Popov | last post by:
Hi, I'm trying to upload a file and I do that with this code, but there is a thing which doesn't work. I can't understand how to check if it isn't written the path to the file(the text field of...
4
by: R Reyes | last post by:
I am coding a forum and am having problems passing around the attachment file (as an HtmlInputFile) from page to page. Sometimes the users may want to preview their posts with the attachment specs...
5
by: shimonsim | last post by:
Hi, I need to upload pictures from client machine and I am using HtmlInputFile control I set validator to make sure that file has correct expention but if one of the files has incorrect extention...
5
by: Ariel Dolan | last post by:
Can I use HtmlInputFile to only get the selected file name but not actually upload the file? Clicking the control's Browse button let's the user select a file. All I need is the HtmlInputFile...
1
by: Brad | last post by:
The following code work on my pc (win2003 server) but does not work when deployed to a server (win2000 server). For count As Integer = 1 To 4 Dim input As New HtmlInputFile input =...
3
by: Rik Moed | last post by:
Hi, I am having a problem with Excel 2003 worksheets when I upload them using the HtmlIputFile. After the upload, I start to download the worksheet and it appears to be currupt. I recieve the...
7
by: Buddy Ackerman | last post by:
I created this class Public Class HTMLFileInput : Inherits System.Web.UI.HtmlControls.HtmlInputFile Public Property Data As String Get Return ViewState("HTMLFileInput.Data") End Get Set...
2
by: Sean Carey | last post by:
I converted a C# Upload app to VB.NET and am down to one error and was hoping someone could help me with te error. I would greatly appreciate help from anyone. Here is the error: ...
3
by: renor321 | last post by:
Hi, I'm trying to use an HTMLInputFile control to upload files to a web server. When I run this on my local computer (Windows XP, .Net 1.1), it works just fine. When I deploy the app to my dev...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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...
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,...
0
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...

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.