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 :)
19 19071
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.
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?
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\)
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 :)
I also have the importFolder defined as
private const string importFolder = @"C:\Uploads\";
Thank you.
M :)
Ok, so do the users ever actually upload the file to you and you write it out to the directory?
For instance: -
string filename = myFileUpload.FileName;
-
byte[] filebytes = myFileUpload.FileBytes;
-
string path = myLogPath;
-
string pathandfile = path+@"\"+filename;
-
try
-
{
-
FileInfo fi = new FileInfo(pathandfile);
-
FileStream fs = fi.Open(FileMode.Create, FileAccess.Write);
-
fs.Write(filebytes,0,filebytes.Length);
-
fs.Flush();
-
fs.Close();
-
fs.Dispose();
-
}
-
catch (Exception ee)
-
{//todo: log an error??
-
-
}
-
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 :)
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.
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 :)
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 :(
@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 :)
Think of silverlight as a mix between flash and java applets. That's how I look at it.
@Plater
I don't know about the "Flash" part....
Have you tried using it before?
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.
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.
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.
Very interesting - thank you for your help. I guess it is time I bit the bullet and started to study Silverlight.
:)
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.
OK, here's a Draft of the article. It might move around or change a bit, but you can read it now.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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: ...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |