用winform 上传文件到IIS7.5怎么弄
string fileNamePath = txtFileName.Text.Trim();
string uriString = txtServerPath.Text.Trim();
string fileName = fileNamePath.Substring(fileNamePath.LastIndexOf("\\") + 1);
string fileNameExt = fileName.Substring(fileName.LastIndexOf(".") + 1);
if (uriString.EndsWith("/") == false) uriString = uriString + "/";
uriString = uriString + fileName;
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
try
{
byte[] postArray = r.ReadBytes((int)fs.Length);
Stream postStream = myWebClient.OpenWrite(uriString, "PUT");
if (postStream.CanWrite)
{
postStream.Write(postArray, 0, postArray.Length);
label1.Text = fileName + "上传成功!";
}
else
label1.Text = "文件目前不可写!";
postStream.Close();
linkLabel1.Text = "查看上载的文件";
for (int i = linkLabel1.Links.Count - 1; i > -1; i--)
linkLabel1.Links.Remove(linkLabel1.Links[i]);
linkLabel1.Links.Add(0, linkLabel1.Text.Length, uriString);
}catch (WebException errMsg){
label1.Text = "上传失败:" + errMsg.Message;
}string fileNamePath = txtFileName.Text.Trim();
string uriString = txtServerPath.Text.Trim();
string fileName = fileNamePath.Substring(fileNamePath.LastIndexOf("\\") + 1);
string fileNameExt = fileName.Substring(fileName.LastIndexOf(".") + 1);
if (uriString.EndsWith("/") == false) uriString = uriString + "/";
uriString = uriString + fileName;
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
try
{
byte[] postArray = r.ReadBytes((int)fs.Length);
Stream postStream = myWebClient.OpenWrite(uriString, "PUT");
if (postStream.CanWrite)
{
postStream.Write(postArray, 0, postArray.Length);
label1.Text = fileName + "上传成功!";
}
else
label1.Text = "文件目前不可写!";
postStream.Close();
linkLabel1.Text = "查看上载的文件";
for (int i = linkLabel1.Links.Count - 1; i > -1; i--)
linkLabel1.Links.Remove(linkLabel1.Links[i]);
linkLabel1.Links.Add(0, linkLabel1.Text.Length, uriString);
}catch (WebException errMsg){
la