Got an issue "Path Not Found" when try to upload an image from Client site to another server(Not the application server). The code is just like below:
FileUpload1.SaveAs(Server.MapPath(#"xx.xx.xx.xx\" + FileUpload1.FileName));
The error occurred after i have deployed the application into the web application server. But when run locally successfully uploaded.
I suspect the File Uploader that run from the application server cannot found the path from client site. It is because the path of the image does not existed in the application server.
There are two question regarding this issue:
1) Is there anyway to resolved this issue.
2) Is there any differences between "FileUpload1.PostedFile.SaveAs()" and FileUpload1.SaveAs()?
Thanks for trying to help me on this.
You should write path as img.Save("c:\\Users\\user\\Desktop\\Barcodes\\1.png", System.Drawing.Imaging.ImageFormat.Png);
Related
I have a web application to upload file. Application first store file to local server and then move to NAS path. Application is using System.IO.File.Move method of C# to move file from local server to NAS.
I am seeing strange issue. After login to application first upload works fine. but if upload another file immediately,it fails. If I wait for 3-5 minutes after a file upload and try to upload file again. it works.
I have tested the connectivity from local server to NAS, it is fine.
Same web application was running on another server, we have stopped application on that server and moved to this server. This issue is happening only on new server not on old server.
Error message:The specified network name is no longer available.
Line of code which throw error: File.Move(sourceFilePath,DestinationFilePath)
Also I was trying to see if connection to NAS path has issue. So what I did is that just before the line of code which is throwing error I added a condition:
If(!File.Exist(DestinationFilePath)){ throw new Exception(<some message>)
After adding this check application is working fine. I am not sure how?
Firstly let me describe my setup.
I have a REST Telerik Reporting service. The service operates with TRDX file (have a requirement to have reports in this template format). I also have a console application, which is periodically started by a windows service. This console application uses ReportProcessor class to print reports directly to a printer.
Now the problem.
ReportProcessor throws an exception when trying to access the reports using UriReportSource, when these report files are hosted in IIS together with the REST Reporting service. Browsing and Anonymous Authentication are enabled on IIS for the Reports folder. The error that's thrown is:
The remote server returned an error: (404) not found.
However reports are printed when TRDX files are located in the same folder as the console application.
Solved my own question by trial and error.
My reports were located in the REST service's subdirectory. So I was trying to set the Uri to the reports URL something like this:
UriReportSource reportSource = new UriReportSource {
Uri = "http://localhost/myTelerikRESTService/Reports/samplereport.trdx"
};
And I was obviously getting 404 error since the request to the that path would be handled by the service.
Trying to specify a physical path (c:\inetpub\wwwroot\myTelerikService\Reports\samplereport.trdx) also ended up in error: something like the path format is not supported.
Finally I've tried this Uri: /inetpub/wwwroot/myTelerikService/Reports/samplereport.trdx, that maps to the physical location.
And it worked!
EDIT:
I really should've read this https://www.w3.org/Addressing/URL/uri-spec.html before working on this issue. Apparently I had no firm understanding of what a URI is! Feeling really dumb now.....
I have uploaded a .pptm file on windows 2003 server in a website directory folder. I get a link to the file like www.domainname/media/CLT/ResourceUploads/4021161/proposal%20sample.pptm when I type in the link in the browser address bar I get this error
Gateway Timeout Server error - server xx.xxx.xxxx.176 is unreachable at this moment. Please retry the request or contact your adminstrator.
If I change the extension of the same file to .ppt or .pptx then the document downloads fine.
I have also tried a different sample file (available on this link http://greenvsa.wikispaces.com/file/detail/proposal+sample.pptm) but the result is still the same.
Any ideas or any direction I shall look into? thanks
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
I need to upload files from my asp.net (C#) page residing in the web server to a remote server.
I managed to upload files to remote server from localhost using this code:
string serverPath = "\\\\xx.xxx.xx.xx\\Folder\\" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(serverPath);
But after I published this code to my web server, it stopped working with the error "The network path was not found."
I have looked at a few solutions which suggest using UNC network share and implementing impersonation.
I couldn't figure out how to apply these solutions.
Can someone please give an example, or suggest a simpler solution.
Thanks!!
In FileUpload1.PostedFile.SaveAs(path), path is physical path of file, No Url. You must check:
is Physical folder Exsist?
is You have access to folder?
if answer of both question is true check this code:
string serverPath = #"\\xxx.xxx.xxx.xxx\Folder\";
if (!System.IO.Directory.Exists(serverPath))
System.IO.Directory.CreateDirectory(serverPath);
FileUpload1.PostedFile.SaveAs(serverPath + FileUpload1.FileName);
The account your application runs under must have write permissions to the folder you are trying to upload the file to: \\xx.xxx.xx.xx\Folder\. So you will have to configure the application pool in IIS to run under an account that will have sufficient permissions. Go to the application pool properties in the IIS management console where you will be able to specify an account to be used to run the application. By default it uses a built-in account which won't have any access to shared resources. Take a look at the following article which explains how to do so.
You need a virtual directory on your webserver to upload to. In code you'll have to use Server.Mappath("virtual path") function to get its server path and then save to it.