C# WinForm 文件上传下载 收藏 /**//**//**//// /// WebClient 上传文件至服务器 /// /// 文件名,全路径格式 /// 服务器文件夹路径 /// 是否需要修改文件名,这里默认是日期格式 /// public static bool UploadFile(string localFilePath, string serverFolder,bool reName)
{ string fileNameExt, newFileName, uriString; if (reName)
{ fileNameExt = localFilePath
Substring(localFilePath
LastIndexOf("
") + 1); newFileName = DateTime
ToString("yyMMddhhmmss") + fileNameExt; } else
{ newFileName = localFilePath
Substring(localFilePath
LastIndexOf("")+1); } if (
serverFolder
EndsWith("/") &&
serverFolder
EndsWith(""))
{ serverFolder = serverFolder + "/"; } uriString = serverFolder + newFileName; //服务器保存路径 /**//**//**//// 创建 WebClient 实例 WebClient myWebClient = new WebClient(); myWebClient
Credentials = CredentialCache
DefaultCredentials;