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

Processing Files

Hello,

I am having a problem with users uploading a file. Basically the way my
application works is that a user will select a file from the system
(csv) and I will take that file and do some processes on it. I am not
saving the file or making any changes to it.

Once I try to parse the file, I get the following error:

Exception Details: System.IO.FileNotFoundException: Could not find file
"C:\WINDOWS\system32\file.CSV".

notice that the path given is C:\windows\system32. but i had selected
file.csv (which exists) from another directory (c:\file.csv).

The place where it crashes on the code is:

using(StreamReader sr = new StreamReader
(inputFile.PostedFile.FileName)
{
string line = null;
int ln = 0;
while((line = sr.ReadLine()) != null)
{
string[] fileFields = splitRx.Split(line);
ln++;
fields.Add(fileFields); //Save all the data for later
}
}

Thank you in advance for your help
Shahid

Mar 10 '06 #1
8 1316
Shahid,

How do your users select the file to be processed? Are you using an
OpenFileDialog? If so, you should be able to programmatically get the
path of the file. Also, look into the DirectoryInfo class to set the
path of a file. Let me know if this helps, if not I have some sample
code somewhere on my harddrive I could find and paste in for you.

~ Justin

Mar 10 '06 #2
Hi Justin,

Thank you for response. I have this for my file dialog - <INPUT
class="box1" id="inputFile" type="file" name="inputFile"
runat="server">

If you can provide me with sample code, it would be greatly
appreciated.

Thank you,
Shahid

Mar 10 '06 #3
Shahid,

I'm not sure if I totally understand what you're doing. Is this a
webservice? Please give some details about the project.

Mar 10 '06 #4
It is a webapplication using C#.

I just need to go through the file that the user provides so I can take
the data and store it on the database.

Mar 10 '06 #5
Shahid,

I'm sorry, I have little to no experience with webservices, so I don't
know what is different and what is the same as programming local
applications. I would suggest posting to the
microsoft.public.dotnet.framework.webservices board. You should find
what you need there. Good luck.

~ Justin

Mar 10 '06 #6
Shahid,
If you want to work with an uploaded file you need to save it to the
filesystem at the location you want first.

HttpPostedFile myFile = inputFile.PostedFile

myFile.SaveAs( Server.MapPath("files/"+myFile.FileName);
using StreamReader sr= new
StreamReader(Server.MapPath("files/"+MyFile.FileName)
.... etc
that's untested code, but I think it gets the idea across.

I think you can also work with the file contents in memory without saving
it, if that's your preference.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Shahid" wrote:
Hello,

I am having a problem with users uploading a file. Basically the way my
application works is that a user will select a file from the system
(csv) and I will take that file and do some processes on it. I am not
saving the file or making any changes to it.

Once I try to parse the file, I get the following error:

Exception Details: System.IO.FileNotFoundException: Could not find file
"C:\WINDOWS\system32\file.CSV".

notice that the path given is C:\windows\system32. but i had selected
file.csv (which exists) from another directory (c:\file.csv).

The place where it crashes on the code is:

using(StreamReader sr = new StreamReader
(inputFile.PostedFile.FileName)
{
string line = null;
int ln = 0;
while((line = sr.ReadLine()) != null)
{
string[] fileFields = splitRx.Split(line);
ln++;
fields.Add(fileFields); //Save all the data for later
}
}

Thank you in advance for your help
Shahid

Mar 10 '06 #7
inputFile.PostedFile.FileName will contain the name of the file as it
existed on the client machine. The only reason that it's even available
is just for some added info in case you want to name the file the same
on the server, etc. What you actually want to use to accomplish this is
....

using(StreamReader sr = new
StreamReader(inputFile.PostedFile.InputStream))

Bruce Dunwiddie
http://www.csvreader.com

JustinC wrote:
Shahid,

I'm sorry, I have little to no experience with webservices, so I don't
know what is different and what is the same as programming local
applications. I would suggest posting to the
microsoft.public.dotnet.framework.webservices board. You should find
what you need there. Good luck.

~ Justin


Mar 11 '06 #8
Thank you very much! That worked perfectly fine.

Mar 14 '06 #9

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

Similar topics

9
by: Hayko Riemenschneider | last post by:
Hi! I've got me an XSL tranformation stylesheet for my XML file. In the XSL file I now wish to use PHP to do some scripting. So I thought I'll use the PIs like this: ...
6
by: Anders Søndergaard | last post by:
Hi, I'm trying to process a large filesystem (+20 million files) and keep the directories along with summarized information about the files (sizes, modification times, newest file and the like)...
1
by: Chery | last post by:
I used dataset to merge 2 XML files having the same structure. I managed to merge these 2 XML files but how can I write a processing instruction to link the merged file to the existing XSL...
6
by: soren juhu | last post by:
Hi, I am developing a C Program for reading over a million files of size 1 kilobytes each and sending the contents to another program using some middle ware. I need some help on designing the...
0
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing'...
5
by: Joe Reazor | last post by:
I've got an asp.net page that has approximately 1,440 controls on it. You must think I'm crazy, but we need to have the page organized in this fashion. As you can imagine, the page takes a very...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: dmoran21 | last post by:
I am working with some files that I need to do some processing with. Essentially, these files contain rainfall reports from various automated rain gauges. These reports are given in 15 minute...
4
by: ferrad | last post by:
I have not used Python before, but believe it may be what I need. I have large text files containing text, numbers, and junk. I want to delete large chunks process other bits, etc, much like I'd...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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...

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.