473,385 Members | 1,325 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,385 software developers and data experts.

Error:Could not find a part of the path

132 100+
Hi there.

I have an ASP.Net form with C# which allows a user to browse to a file and then add the file details to a listbox; I am using a listbox to hold the details for multiple files to enable batch processing.

For each file, I then copy it to a folder called C:\uploads and the file is processed from there.

For the copy command I am using:

File.Copy(listFileName.Text, importFolder);

and it is here that I receive a message:

Could not find a part of the path 'C:\Uploads\'.

Any ideas how to get passed this please, as I have tried a few ideas from the web but none have been applicable so far?

Thank you.

Mark :)
Dec 4 '08 #1
19 19071
Curtis Rutland
3,256 Expert 2GB
This doesn't make any sense to me....

You say you're using ASP.NET? How are you getting any file details without uploading the file? Unless you are serving the app from the same machine that you are browsing from, you shouldn't be able to browse the user's file system.

Please clarify what you're doing.
Dec 4 '08 #2
Plater
7,872 Expert 4TB
The files are on the Clients computer, not on the server computer right?
So when the server executes the SERVER code of File.Copy(), it cannot find these files?
Dec 4 '08 #3
shweta123
692 Expert 512MB
Hi,

To solve the error you are getting , you can do the following things:

1> You should give the filepath as C:\\upload\\
2> You should specify @ chracter for giving special characters.
e.g FilePath = @(c:\upload\)
Dec 4 '08 #4
E11esar
132 100+
Hi again.

I am using an asp:FileUpload to enable browsing to a folder on the local server (currently my laptop) and then adding the details of

FileUpload1.PostedFile.FileName

to a ListBox, as I need to load and process multiple files, so this was a best way idea for me to accommodate this requirement.

I then use a foreach on the listbox details and deposit the listbox text details to a File.Copy() command, so for example

listbox.text = "c:\filename.ext" so this is used in the sourceDirectory part of the Copy command.

I have a constant called importFolder, which is set to "c:\uploads" so the copy is then made up of

File.Copy(sourceDirectory, importFolder);

I think I can see what maybe going amiss here (as I type this) I am not adding in the fileName to the importFolder, so I need to append this to the directory "c:\uploads"..?

Thank you.

Mark :)
Dec 4 '08 #5
E11esar
132 100+
I also have the importFolder defined as

private const string importFolder = @"C:\Uploads\";

Thank you.

M :)
Dec 4 '08 #6
Plater
7,872 Expert 4TB
Ok, so do the users ever actually upload the file to you and you write it out to the directory?

For instance:
Expand|Select|Wrap|Line Numbers
  1. string filename = myFileUpload.FileName;
  2. byte[] filebytes = myFileUpload.FileBytes;    
  3. string path = myLogPath;
  4. string pathandfile = path+@"\"+filename;
  5. try
  6. {
  7.   FileInfo fi = new FileInfo(pathandfile);
  8.   FileStream fs = fi.Open(FileMode.Create, FileAccess.Write);
  9.   fs.Write(filebytes,0,filebytes.Length);
  10.   fs.Flush();
  11.   fs.Close();
  12.   fs.Dispose();
  13. }
  14. catch (Exception ee)
  15. {//todo: log an error??
  16.  
  17. }
  18.  
Dec 4 '08 #7
E11esar
132 100+
Hi again, I have just solved it.

The answer was to append the fileName as mentioned above, hence I used the following code to solve the problem:

foreach (ListItem listFileName in fileList.Items)
{
try
{
.
.
.
string sourcePath = listFileName.Text;
string destPath = Path.Combine(importFolder,Path.GetFileName(listFil eName.Text));

//Copy file, overwriting if necessary
File.Copy(sourcePath, destPath, true);
.
.
.

This then has done the trick.

Thank you for your help.

M :)
Dec 4 '08 #8
Curtis Rutland
3,256 Expert 2GB
Just to save you this headache later....

This isn't going to work once you start testing it from a real webserver rather than your local machine. The server doesn't have any access to your filesystem, so saying File.Copy or whatever will look on the server's file system not the client's. It's working right now because those are the same; you're browsing from your server.

Remember that all .net code is processed and handled on the server.
Dec 4 '08 #9
E11esar
132 100+
Oh that is not good news then..!

Sorry to be a pain but what should I do in this case for when this is running on the server?

Is it best to use the asp.FileUpload and the SaveAs method to save the target file to the uploading directory?

If this is the case then I will be back at square one as I need to process a batch of files and didn't want to add FileUpload's to the web form.

Also to add to this, I am now finding that my current approach is copying across an empty file, whereas the source file is greater than zero bytes..?

Looks like my premature "it is working" was unfounded..!

M :)
Dec 4 '08 #10
Curtis Rutland
3,256 Expert 2GB
Well.....ASP.NET isn't going to be the best way to process multiple files, unless you want to dynamically create multiple FileUpload controls. If it were me...I'd look into using a Silverlight control and a web service. When you "save" files in silverlight, you are actually using local storage on the client's computer. So you can "save" a batch of files locally, and then process them. Write a web service or WCF service that will take a byte[] or maybe a List<byte[]> to do them all at once and do the batch processing, and return a status.

Well, your simple project just got much more complicated :(
Dec 4 '08 #11
Frinavale
9,735 Expert Mod 8TB
@insertAlias
This is one of the reasons why most web sites have restrictions on the number of files you can upload.

@insertAlias
I had no idea that silverlight could do this....
This is a very good excuse to check out silverlight tonight :)
Dec 4 '08 #12
Plater
7,872 Expert 4TB
Think of silverlight as a mix between flash and java applets. That's how I look at it.
Dec 4 '08 #13
Frinavale
9,735 Expert Mod 8TB
@Plater
I don't know about the "Flash" part....
Have you tried using it before?
Dec 4 '08 #14
Curtis Rutland
3,256 Expert 2GB
It's a lot like flash in some ways...it's a rich client side plugin. But you really don't program it the same way...it's not on a timeline.

It is more like an applet than anything, but with much less overhead.
Dec 4 '08 #15
Curtis Rutland
3,256 Expert 2GB
Videos : The Official Microsoft Silverlight Site

This URL might be of interest. It's a sample on how to use silverlight to upload a file through a webservice (i think...i'm pretty sure this is the video I watched that showed that ;))

Now, if this is the video I think it is, i think it uses a REST service, but you could write that as an ASMX or WCF service just as easily, and use a real service reference in your app.
Dec 4 '08 #16
Curtis Rutland
3,256 Expert 2GB
Just to let you know, I'm working on writing a program like the one I described, and I will write an article about it, describing how.

It should be done in a day or so.
Dec 5 '08 #17
E11esar
132 100+
Very interesting - thank you for your help. I guess it is time I bit the bullet and started to study Silverlight.

:)
Dec 7 '08 #18
Curtis Rutland
3,256 Expert 2GB
OK, sorry, things have taken much longer than I wished, but I have finished the project. I will write the article about the project soon. It was an interesting one, that's for sure.

I'll post a link in this thread to the article once it comes up.
Dec 19 '08 #19
Curtis Rutland
3,256 Expert 2GB
OK, here's a Draft of the article. It might move around or change a bit, but you can read it now.
Dec 20 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Christopher Parent | last post by:
I have perused through the groups and a couple C++ manuals and haven't been able to figure this one out. Maybe I'm staring at it too much. Here's the setup, I have 2 files. One is a library and one...
11
by: Etienne Charland | last post by:
Hi, I have a solution containing 6 C# projects; 1 WinForms project and 5 class libraries. I didn't have any problems until recently. I added a new project containing reports. I am using...
3
by: TC | last post by:
Hello, I'm trying to read a text file located in the top folder of the virtual directory and I'm receiving the following error: "Could not find a part of the path" Below is the code that...
0
by: jessica | last post by:
Hi, I got a problem "Could not find a part of the path". On my loca machine I mapped the V:\LoggerNet to a remote server folder where th real-time data come in. I checked the file, it gets updated...
14
by: Gianfranco | last post by:
Hi everybody, First of all, sorry for my english if it isn't perfect ;-p I have an error in an asp.net application. I have win2003 server, with iis 6. I'm developping with visual studio...
2
by: rouqiu | last post by:
Hello, My code is this: string fileName = "settings/tabs.xml"; XPathDocument doc = new XPathDocument(fileName); However, instead of searching files under the current IIS directory, the IIS...
1
by: dotNetDave | last post by:
I keep getting the following error on one of my web service pages: Parser Error Parser Error Message: Could not create type 'SyPixx.Web.ClearService.ConfigureAlarms'. Source Error: Line 1: ...
3
by: Nitinkcv | last post by:
Hi, While trying to run my app im getting the error Could not find a part of the path "c:\inetpub\wwwroot\Do not Delete\dbglobal.config". I checked and found that there is no Important_Do not...
1
by: ipramod | last post by:
Hi, I have a codebase which contains project for all the DLL's and another project for all UI presentations. When I try to open an aspx page on Visual Studio editor, I get following error on...
3
by: =?Utf-8?B?SGVyYg==?= | last post by:
I've developed an ASP.NET website that runs fine on my local WinXP IIS and on my server's IIS, both are IIS6.0 The site uses a master page that has the following declaration: <%@ Master...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.