小技巧——从网站上下载指定的文件
#region 从网站上下载指定的文件 return string
/// <summary>
/// 从网站上下载指定的文件
/// </summary>
/// <param name="request">Request</param>
/// <param name="filePathOfURL">FillPath,如"http://localhost/CSharpWebApp/asd.doc"</param>
/// <returns>string</returns>
/// COM-->Microsoft XML,v5.0 using MSXML2;
public static string FileDownLoadFromWebSite(System.Web.HttpRequest request,string filePathOfURL)
{
string rtn = "";
try
{
string Url = "http://dotnet.aspx.cc/Images/banner.gif";
//Url = "http://localhost/CSharpWebApp/asd.doc";
Url = filePathOfURL;
string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);
string StringFilePath = request.PhysicalApplicationPath;
if(!StringFilePath.EndsWith("\\"))
StringFilePath += "\\";
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET",Url,false,null,null);
_xmlhttp.send("");
if( _xmlhttp.readyState == 4 )
{
if(System.IO.File.Exists(StringFilePath + StringFileName))
System.IO.File.Delete(StringFilePath + StringFileName);
System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
w.Write((byte[])_xmlhttp.responseBody);
w.Close();
fs.Close();
rtn = "文件已经得到。<br><a href='" + request.ApplicationPath + "/" + StringFileName +"' target='_blank'>";
//Response.Write ("文件已经得到。<br><a href='" + Request.ApplicationPath + "/" + StringFileName +"' target='_blank'>");
rtn = rtn + "查看" + StringFileName + "</a>";
}
else
rtn =_xmlhttp.statusText;
}
catch{}
return rtn;
}
#endregion 从网站上下载指定的文件 return string
/// <summary>
/// 从网站上下载指定的文件
/// </summary>
/// <param name="request">Request</param>
/// <param name="filePathOfURL">FillPath,如"http://localhost/CSharpWebApp/asd.doc"</param>
/// <returns>string</returns>
/// COM-->Microsoft XML,v5.0 using MSXML2;
public static string FileDownLoadFromWebSite(System.Web.HttpRequest request,string filePathOfURL)
{
string rtn = "";
try
{
string Url = "http://dotnet.aspx.cc/Images/banner.gif";
//Url = "http://localhost/CSharpWebApp/asd.doc";
Url = filePathOfURL;
string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);
string StringFilePath = request.PhysicalApplicationPath;
if(!StringFilePath.EndsWith("\\"))
StringFilePath += "\\";
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET",Url,false,null,null);
_xmlhttp.send("");
if( _xmlhttp.readyState == 4 )
{
if(System.IO.File.Exists(StringFilePath + StringFileName))
System.IO.File.Delete(StringFilePath + StringFileName);
System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
w.Write((byte[])_xmlhttp.responseBody);
w.Close();
fs.Close();
rtn = "文件已经得到。<br><a href='" + request.ApplicationPath + "/" + StringFileName +"' target='_blank'>";
//Response.Write ("文件已经得到。<br><a href='" + Request.ApplicationPath + "/" + StringFileName +"' target='_blank'>");
rtn = rtn + "查看" + StringFileName + "</a>";
}
else
rtn =_xmlhttp.statusText;
}
catch{}
return rtn;
}
#endregion 从网站上下载指定的文件 return string
· WPF 使用GDI+提取图片主色调并生成Mica材质特效背景
· golang遍历处理map时的常见性能陷阱
· .NET8带来的一些新特性
· 聊一聊 C# NativeAOT 多平台下的函数导出
· 单一职责原则的思维:为什么你的代码总在"牵一发而动全身"
· 精选 12 款开源、免费、美观的 Vue 后台管理系统模板!
· 独立开发者的在线客服系统:从 0 到 300 余万次会话,1700 余万条消息
· 如何实现本地大模型与MCP集成
· 玩客云 OEC/OECT 笔记
· 鸿蒙仓颉语言开发实战教程:实现商品分类页