I have a WPF client app. I'm try to get access to c:\programdata\, which I can clearly see is available. When I use File.Copy() and c:\programdata\ as the destination, I get this error:
Could not find a part of the path
Anyone know what is wrong?
The File.Copy documentation states that destFileName is:
The name of the destination file. This cannot be a directory or an existing file.
You say you are passing C:\\programdata\\. That is a directory. You have to provide the path and the file name.
For example:
File.Copy("C:\\programdata\\source.txt", "C:\\programdata\\dest.txt");
Related
My code is
after run on Azure it say:
{
"Message": "Cannot create 'D:\\home\\site\\wwwroot\\DataFile' because a file or directory with the same name already exists."
}
how to resolve this??? My code tells it if the directory exists will be ignored and pass not created...why does it try to create and tell can not create because the directory exists???
Work in local work well...no error...the problem appears when run in azure
If I remove the code create a directory, It will error that the path does not exist and it doesn't create and write file...
In Azure
In Local
This code work OK
In Azure it cause error be cause in D:\home\site\wwwroot\DataFile have a DataFile, it is a file,
I use the Kudu, (In App Service in Azure, search Advanced Tools)
then remove the file DataFile, then all things OK
Thanks all for support me!
I am building a web application using WCF. I need to full path of a file to open and upload it to web service.
What I am doing is first opening a file by its full path, then take stream of it and finally upload it to service. My code is below
string Path = Server.MapPath( FileUpload1.PostedFile.FileName);
System.IO.Stream fileStream = File.OpenRead(#Path);
I can't get full path of the file for security reasons.
How can I read the file that users select?
Server.MapPath(FileUpload1.FileName) is the path to a file on the server. You cannot get the full path of the client machine of the file Using the FileUpload.
There is no need for the full client path to access it. You can use the FileBytes
property in order to read the contents of uploaded file.
As others have already suggested there's no reason you need the file path to the client in order to save a file on your server. In the case you need some clearer explanation for this, then please refer to these answers:
https://stackoverflow.com/a/3077008/2196675
https://stackoverflow.com/a/1130718/2196675
I'm using FileUpload.SaveAs() function of C# to upload files to the server but I want to save the files on another partition. Let us say, save the files on Drive D of the server instead on the current drive which is Drive C. Please share your thoughts. Thanks is advance.
I have learned that using full path such as
FileUpload.SaveAs("D:\FileUpload");
will save the file outside the web server.
Check this out.
To simplify the question, how can I upload files on the other partition of the server that hosts my web app?
Based on the documentation from http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas.aspx, the String filename is the full path name of the location to save. Meaning you should be able to do so e.g:
FileUpload.SaveAs("D:\where_you_want_to_save")
By the way what have you tried and what error did you get?
Looking at the example on MSDN, it would appear that .SaveAs() accepts a fully qualified file name as a parameter. You could potentially use a Path object to cleanly build a path for the file, or just specify one directly as a string:
uploader.SaveAs("d:\\someFolder\\someFile.ext");
Resolved this by using Virtual Directory of IIS and providing admin credentials for authentication
Hello I am attempting to copy a file over to a shared network but I continue getting the error The filename, directory name, or volume label syntax is incorrect. Could someone please catch what I am doing incorrectly. Also my Application is running using ASP.NET MVC3, Thanks!
copy code
File.Copy(#path, #Properties.Settings.Default.SharedMappedOutput);
The path is a parameter: C:\log\12345.pdf
Properties.Settings.Default.SharedMappedOutput Path: \\vfler_xx\evl_xx\VT\ .
What I want to accomplish: I want to copy the file from Path (filename) to SharedMappedOutput (directory)
Extra information
Windows Server 2008 R2
IIS 7.5
ASP.NET MVC3 C#
EDIT
I have changed my code with the help of #Steve, but now it is saying I do not have access to a path that I did not specify.
String dest_path = Properties.Settings.Default.SharedMappedOutput;
File.Copy(#path, Path.Combine(dest_path, Path.GetFileName(path)));
ERROR
Access to the path 'c:\windows\system32\insetsrv\12345.pdf' is denied
I did not specify this path, I am not sure why it is trying to access this path.
Link to the new problem
https://stackoverflow.com/questions/16179585/iis-acccess-to-the-path-c-windows-system32-inetsrv-12345-pdf-is-denied
Thank you. Please let me know if there is any questions or misunderstanding in the question. Thanks in advance again.
File.Copy doesn't copy a directory to another directory, but just a filename.
Your c:\log seems to be just the name of a directory and as stated by the documentation at MSDN this doesn't work
To copy all the file in the source path you could write this
string destPath = Properties.Settings.Default.SharedMappedOutput;
foreach (string aFile in Directory.GetFiles(path, "*.*"))
File.Copy(aFile, Path.Combine(destPath, Path.GetFileName(aFile)));
EDIT
Seeing the comment about the real source name then the answer is still partially valid because also the destination should be a filename and not a directory. So the answer becomes
string sourceFile = #"C:\log\12345.pdf";
string destPath = Properties.Settings.Default.SharedMappedOutput;
File.Copy(sourceFile, Path.Combine(destPath, Path.GetFileName(sourceFile)));
This has something to do with using a UNC path if I remember correctly. Map the share as a mapped drive and it will work like a charm.
here is an example on mapping the unc path to a mapped drive.
http://www.codeproject.com/Articles/6847/Map-Network-Drive-API
I wrote some code to upload files to amazon S3, if I put a full file path manually It successfully uploads the file from my computer. What I'm trying to do is use a file upload control and store the full path in a variable so that I can use it for my amazon method. Ive read everywhere it seems that the browser won't let you get the full file path for security reasons.
How can I get the full file path? Should I just store the files on my webserver and point my amazon method to the server path, and then use the file upload control to tell it what the filename is? I wish I could just do a straight shot to amazon...
First we have to save the file path and then we take it from
string filepath=Path.GetFullPath(UploadFile1.FileName.toString());
I came across this link which has a great tutorial and even gives you a working sample project. (this is different from the code that the .net SDK includes...) http://aws.amazon.com/articles/774?_encoding=UTF8&jiveRedirect=1
We can't take full path in HTML or JS as it violets security so whenever you try to see the path it shows fakepath
so to resolve this issue you can make a seprate folder and you can store the uploaded file there and in the code you can take that folders path as default and use it as a absolute path.
You can get the full path using Python Tkinter but it is limited for desktop app.