dot_net_lover2
چهارشنبه 05 مرداد 1384, 11:19 صبح
سلام من واسه اینکه یک فایل را upload کنم از این sample مربوط به MSDN استفاده کردم با این تفاوت که من میخواهم با Win app و Web service این کار را انجام بدم
MSDN Sample Code
Console.Write("\nPlease enter the URL to post data to : ");
String uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URL");
string fileName = Console.ReadLine();
Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",fileName);
// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",
Encoding.ASCII.GetString(responseArray));
[C#]
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);
}
}
اینم کده من تا اینجا
WebClient myWebClient = new WebClient();
string url = "http://server/savefileonserver";
Uri myUri = new Uri(url);
myWebClient.UploadFile(myUri.ToString(),"POST",openFileDialog1.FileName.ToString());
و اینم Error که میده
The remote server returned an error: (405) Method Not Allowed.
ممنون میشم ، راهنمایی کنید.
MSDN Sample Code
Console.Write("\nPlease enter the URL to post data to : ");
String uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URL");
string fileName = Console.ReadLine();
Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",fileName);
// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",
Encoding.ASCII.GetString(responseArray));
[C#]
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);
}
}
اینم کده من تا اینجا
WebClient myWebClient = new WebClient();
string url = "http://server/savefileonserver";
Uri myUri = new Uri(url);
myWebClient.UploadFile(myUri.ToString(),"POST",openFileDialog1.FileName.ToString());
و اینم Error که میده
The remote server returned an error: (405) Method Not Allowed.
ممنون میشم ، راهنمایی کنید.