PDA

View Full Version : مشکل با URI



dot_net_lover2
چهارشنبه 05 مرداد 1384, 10: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.

ممنون میشم ، راهنمایی کنید.

M.GhanaatPisheh
پنج شنبه 06 مرداد 1384, 14:19 عصر
از HTTPRequest و HTTPResponse از Namespace

System.Web استفاده کن

تو MSDN راجع بهش تحقیق کن.

مشکلی داشتی Post بزن.

dot_net_lover2
پنج شنبه 06 مرداد 1384, 16:38 عصر
همینطور که گفتم من از Web service استفاده میکنم ، بخاطر اینکه در این Project باید فایلهای یک دایرکتوری در Client بررسی شود و در صورت تغییر به صورت خودکار توسط web service مورد نظر Upload شود(بر روی یک Server) و نیز بر روی کامپیوتر Admin (کامپیوتر Admin از کامپیوتر Server مجزا میباشد)
با یک Win App شبیه به Client و با این تفاوت که یک Directory خاص بر روی Server را چک میکند عملیات فوق به صورت برعکس(Downlaod) انجام میشود.

به همین دلایل بهترین راه حل من استفاده از Web Client است.
لطفا اگر راه حل بهتری دارید ، راهنمایی کنید.

با تشکر