Answered by:
file not getting upload in server

Question
-
namespace Fileupload { class Program { static void Main(string[] args) { String uriString = "http://xxx.xx/portal/"; string filepath = string.Empty; filepath = "D:/FileUpload/DataTransferLogfile.txt"; Console.WriteLine("filepath" +filepath); try { WebClient myWebClient = new WebClient(); //myWebClient.Credentials = new NetworkCredential("administrator", "selva@1123"); // myWebClient.Headers.Add(HttpRequestHeader.UserAgent, "anything"); byte[] responseArray = myWebClient.UploadFile(uriString,"POST",filepath); System.Text.Encoding.ASCII.GetString(responseArray); myWebClient.Dispose(); Console.WriteLine("file upload"); Console.ReadLine(); } catch(WebException we) { Console.WriteLine(we.Message); Console.ReadLine(); } } } }
code run without error but file is not uploading in server,,
please help me!!
Friday, July 20, 2012 2:29 PM
Answers
-
Hi selvakumars,
Are you sure you have write permission for uploading file on target server?
You can check the error detail description in your IIS server as following:1. Start -> Run "compmgmt.msc"
2. In the left pane of computer management, select System Tools->Event Viewer->System.
In the right pane, you will find the error description which happened when you upload file.
e.g.
-----------------------
The server was unable to logon the Windows NT account 'IUSR_XXXX' due to the following error: Logon failure: the user has not been granted the requested logon type at this computer. The data is the error code.
For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
-----------------------
If it is this case, you should update the permission of uploaded folder.
e.g. If you want to upload files to c:\inetpub\test\UploadedFiles in server,
1. Right click UploadedFiles folder by mouse and select Properties.
2. Click Security tab in Properties window and click Add button, add Authenticated Users.
3. Set the Full Control permission to Authenticated Users.
Try to upload one file again, hope well run...
BingTuesday, July 24, 2012 9:36 AM
All replies
-
Hi selvakumars,
1. You need add one webpage on the server side.
The following code example shows an ASP.NET page(e.g. its name is uploadfile.aspx) that can accept posted files and is suitable for use with the UploadFile method. The page must reside on a Web server. Its address provides the value for the address parameter of the UploadFile method.
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>
<Script language="C#" runat=server>
void Page_Load(object sender, EventArgs e) {
foreach(string f in Request.Files.AllKeys) {
HttpPostedFile file = Request.Files[f];
file.SaveAs("c:\\inetpub\\test\\UploadedFiles\\" + file.FileName);
}
}
</Script>
<html>
<body>
<p> Upload complete. </p>
</body>
</html>
2. Revise your URL as following in your console application:String uriString = "http://xxx.xx/portal/uploadfile.aspx";Any question, don't hesitate to contact with me, please.
Bing
Monday, July 23, 2012 7:52 AM -
Mr.bing.cao, its console application , not web application.
Thanks
Selva
- Edited by miruan Monday, July 23, 2012 7:59 AM
Monday, July 23, 2012 7:57 AM -
Hi,
If you are aware that no error has been thrown and you are checking in right folders, I would suggest enable Network Tracing and debug.
http://msdn.microsoft.com/en-us/library/hyb3xww8.aspx
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
Monday, July 23, 2012 8:07 AM -
Hi selvakumars,
I means your console client application is ok, but you need add one web page on the server side. The console client application sends a file to server side, but on the server side need one web page to recieve this file.
In your case, I think there is not one web page on the server side to recieve the file.
So that code run without error but file is not uploading in server.
BingMonday, July 23, 2012 8:18 AM -
mr.bing
i created asp.net page in web server, its working fine also but i am uploading file in client i am getting tis error "The remote server returned an error: (500) Internal Server Error".
Monday, July 23, 2012 9:43 AM -
Hi selvakumars,
Are you sure you have write permission for uploading file on target server?
You can check the error detail description in your IIS server as following:1. Start -> Run "compmgmt.msc"
2. In the left pane of computer management, select System Tools->Event Viewer->System.
In the right pane, you will find the error description which happened when you upload file.
e.g.
-----------------------
The server was unable to logon the Windows NT account 'IUSR_XXXX' due to the following error: Logon failure: the user has not been granted the requested logon type at this computer. The data is the error code.
For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
-----------------------
If it is this case, you should update the permission of uploaded folder.
e.g. If you want to upload files to c:\inetpub\test\UploadedFiles in server,
1. Right click UploadedFiles folder by mouse and select Properties.
2. Click Security tab in Properties window and click Add button, add Authenticated Users.
3. Set the Full Control permission to Authenticated Users.
Try to upload one file again, hope well run...
BingTuesday, July 24, 2012 9:36 AM