I am using telerik controls in asp.net
For uploading a file i am using, RadUpload
I gone through following links:
http://www.telerik.com/community/forums/aspnet-ajax/upload/get-full-path-from-uplad-control.aspx#1044702
http://www.telerik.com/community/forums/aspnet-ajax/async-upload/how-to-get-full-path-using-radasyncupload-control.aspx
Made Code As Follows:
for (int i = 0; i < RadUpload1.UploadedFiles.Count; i++)
{
string fileName= Server.MapPath( RadUpload1.UploadedFiles[i].GetName());
}
Its giving me path:
E:\WebBasedNewSoft\NewSoft\NewSoft\colnames.xlsx
this is the path where my solution files are stored.
I wanted to get path of file selected for upload.
Eg. if uploaded file is on c drive , it should give me path:
C:\colnames.xlsx
But its not giving me appropriate path.
What mistake am i making?
What should be appropriate line in for loop??
Please help me.
The file path will NEVER contain the path of the client's computers, because the software on the server is never allowed to take a peek inside the clients computer. If the server was alles to see inside the clients computer we would have a security issue.
The path you are getting is the local path at the server to where the file has been uploaded.
Related
So I was trying to upload a 1kb text file to my ftp server but this error comes up:
The remote server returned an error: (553) File name not allowed.
so what's wrong with my code?
WebClient upload = new WebClient();
upload.Credentials = new NetworkCredential("******", "*********");
upload.UploadFile("ftp://xxx.com/public_html", "G:/adress.txt");
It's hard to tell, because it's a server error not a code error. However, as currently written, you're trying to upload the file called adress.txt to become a file named public_html. I suspect there's already a directory with that name, and the conflict is preventing the upload. Try
upload.UploadFile("ftp://xxx.com/public_html/adress.txt", "G:/adress.txt");
instead.
This might not apply to you, but if it is a Linux FTP server:
This may help for Linux FTP server.
So, Linux FTP servers unlike IIS don't have common FTP root directory.
Instead, when you log on to FTP server under some user's credentials,
this user's root directory is used. So FTP directory hierarchy starts
from /root/ for root user and from /home/username for others.
So, if you need to query a file not relative to user account home
directory, but relative to file system root, add an extra / after
server name. Resulting URL will look like:
ftp://servername.net//var/lalala
Instead of:
ftp://xxx.com/public_html
You would need a second slash after the server name in addition to the full file name:
ftp://xxx.com//public_html/adress.txt
I ran into this same issue and it fixed it for me.
Source:
Can't connect to FTP: (553) File name not allowed
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'm trying to download a file using the Tamir SSH library. I'm able to connect to the remote FTP site, upload files to the site, but I'm getting exceptions when trying to download. I've given IIS_IUSRS full control of the local directory as well as ASPNET. I've tested an I'm able to create a text file in the same local directory I'm trying to download to. Any ideas?
string SFTP_HOST = ConfigurationManager.AppSettings["AccentivFtpHost"];
string SFTP_USERNAME = ConfigurationManager.AppSettings["AccentivFtpUsername"];
string SFTP_PASSWORD = ConfigurationManager.AppSettings["AccentivFtpPassword"];
Sftp client = new Sftp(SFTP_HOST, SFTP_USERNAME, SFTP_PASSWORD);
client.Connect(22);
client.Get("test.txt", "c:\\test.txt");
You probably lack a '/' character in the file directory. You may need to put it either in the Get function call before the "test.txt" like "/test.txt" or at the end of your AccentivFtpHost value in the app config file.
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.
I have a problem with my code. My code is using the fileupload control to browse for a filename when you add a filename it processes it and the code runs fine on when it lives on local host, but when I put the code on our prodution server it cannot find the filenames listed by user.
For example if I use the upload control to browse to
B:\MIS\CH Intive\RPTTOFL_3.csv and the code lives on my localhost which know what that file path means it works, but if the code is moved to a production server it may or maynot know what B:/ is or B:/ maybe mapped to something else.
Even if I am browsing to a file on my C drive it will work on if the code is on the machine that the C drive is on, but it will not work if the code is on another machine because obviously that file wouldnt be on that C drive.
Private Function CSV2DataTable(ByVal filename As String) As DataTable
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
MyReader.TextFieldType = FileIO.FieldType.Delimited
.
.
.
What can I do in asp.net to make the filename work correctly?
Ok lets say I get the filename and save it as so
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
now I want to pass the filename to the function above for processing. Do I pass Server.MapPath("~/") + filename as the filename? Also when I am done what do I do to delete the file from the server?
It seems that you are mixing the client and server locations of the file. Before reading the uploaded file, the server-side code must save it on the server (client-side file location is mostly irrelevant at this point). From VS help on FileUpload class: "The code that you write to save the specified file should call the SaveAs method, which saves the contents of a file to a specified path on the server." The online help topic on FileUpload control has enough information (with examples) to achieve what you need.