c#怎么判断上传文件的大小
1个回答
2016-11-13
展开全部
try
public static long GetRemoteHTTPFileSize(string sURL)
{
long size = 0L;
try
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sURL);
request.Method = "HEAD";
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
size = response.ContentLength;
//size = System.Convert.ToInt64(response.Headers["Content-Length"]);
response.Close();
}
catch
{
size = 0L;
}
return size;
}
public static long GetRemoteHTTPFileSize(string sURL)
{
long size = 0L;
try
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sURL);
request.Method = "HEAD";
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
size = response.ContentLength;
//size = System.Convert.ToInt64(response.Headers["Content-Length"]);
response.Close();
}
catch
{
size = 0L;
}
return size;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询