如何在win form应用程序中上传本地服务器(wamp)上的文件 [英] how to upload a file on local Server(wamp) in win form application

查看:63
本文介绍了如何在win form应用程序中上传本地服务器(wamp)上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码,但它执行时出现错误消息msg文本在catch.source文件上存在于驱动器F上我有一个名为New的文件夹在C:/ Wamp / www / New我要上传文件test.the代码如...

private void upload_Click(object sender,EventArgs e)

{

上传(@F: /Rahul.txt);

label2.Text =上传成功完成......;

}

public void Upload(string fileToUpload)

{



尝试

{

FileInfo toUplaod = new FileInfo (fileToUpload);

FtpWebRequest request =(FtpWebRequest)WebRequest.Create(http://127.0.0.1/New/+ toUplaod.Name);

请求。 Method = WebRequestMethods.Ftp.UploadFile;

//request.Credentials = new NetworkCredential(USERNAME,PASSWORD);

流ftpstream = request.GetRequestStream();

FileStream file = File.OpenRead(fileToUpload);

int length = 1024;

byte [ ] buffer = new byte [length];

int bytesRead = 0;



do

{

bytesRead = file.Read(buffer,0,length);

ftpstream.Write(buffer,0,bytesRead);

}

while(bytesRead!= 0);

file.Close();

ftpstream.Close();

< br $>


}

catch

{

MessageBox.Show(错误!连接服务器.itni jaldi nhi chalunga Sir g ..);

}







}

谢谢....

I had used the following code but it executes with error msg texted on catch.source file exists on drive F and i have a folder named as New in C:/Wamp/www/New where i want to upload the file for test.the code is as...
private void upload_Click(object sender, EventArgs e)
{
Upload(@"F:/Rahul.txt");
label2.Text = "Uploading successfully completed...";
}
public void Upload(string fileToUpload)
{

try
{
FileInfo toUplaod = new FileInfo(fileToUpload);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("http://127.0.0.1/New/" + toUplaod.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
//request.Credentials = new NetworkCredential("USERNAME","PASSWORD");
Stream ftpstream = request.GetRequestStream();
FileStream file = File.OpenRead(fileToUpload);
int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;

do
{
bytesRead = file.Read(buffer, 0 ,length);
ftpstream.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
file.Close();
ftpstream.Close();


}
catch
{
MessageBox.Show("Error ! connecting server..itni jaldi nhi chalunga Sir g..");
}



}
Thank you....

推荐答案

我不敢相信你不仅在运行HTTP服务器了http:// localhost,在默认端口上;并且你有一个名为/127.0.0.1的子目录。你更可能不太了解 URI方案 ;实际的URL是http:// localhost / New。



请参阅更多信息: http://en.wikipedia.org/wiki/URI_scheme [ ^ ]。



我也不太确定你是否正在运行任何HTTP服务器。你安装了一个吗?你从来没有提到它,我怀疑你不太明白它是如何工作的。抱歉,如果我错了。



另外,我想要注意的是,没有使用硬编码URL的情况。但是,如果这只是初步测试,那可能就行了。



-SA
I cannot believe that not only you are running HTTP server on "http://localhost", on default port; and that your have a sub-directory named "/127.0.0.1". It''s more likely that you do not quite understand the URI scheme; and you actual URL is "http://localhost/New".

Please see for more information: http://en.wikipedia.org/wiki/URI_scheme[^].

I also not quite sure that you are running any HTTP server at all. Did you install one? You never mentioned it, and I suspect you don''t quite understand how it works. Sorry if I''m wrong about it.

Also, I want to note that there are no situations where using a hard-coded URL is useful. However, if this is just a preliminary test, it''s probably OK.

—SA


这篇关于如何在win form应用程序中上传本地服务器(wamp)上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆