C#利用webrequest计算待下载的文件大小
C#利用webrequest计算待下载的文件大小
string URL = textBox1.Text;
string filetype = URL.Substring(URL.LastIndexOf(".") + 1, (URL.Length - URL.LastIndexOf(".") - 1));
filetypevalue.Text = filetype.ToUpper();
string filename = URL.Substring(URL.LastIndexOf("/") + 1, (URL.Length - URL.LastIndexOf("/") - 1));
namelabel.Text = filename;
System.Net.WebRequest req = System.Net.HttpWebRequest.Create(textBox1.Text);
req.Method = "HEAD";
System.Net.WebResponse resp = req.GetResponse();
long ContentLength = 0;
long result;
if (long.TryParse(resp.Headers.Get("Content-Length"), out ContentLength))
{
string File_Size;
if (ContentLength >= 1073741824)
{
result = ContentLength / 1073741824;
kbmbgb.Text = "GB";
}
else if (ContentLength >= 1048576)
{
result = ContentLength / 1048576;
kbmbgb.Text = "MB";
}
else
{
result = ContentLength / 1024;
kbmbgb.Text = "KB";
}
File_Size = result.ToString("0.00");
sizevaluelabel.Text = File_Size;
}
相关文档:
C# CHM帮助文档生成工具-Sandcastle
为了让我们的开发团队规范文档,并易于交流,最终使用了Sandcastle生成chm格式文档。
一、下载。
我发现有两种Sandcastle可供下载,一个是官方的Sandcastle,另一个是SandcastleGUI(图形界面的)。
前一个是必须安装的,然后再下载个SandcastleGUI,直接使用即可,下载地址为:
......
发生这种问题主要是没有将typelib信息写到注册表,只要调用RegisterTypeLibServer函数则可添加相关信息,参考下面代码。
以下宏定义是我为了简化com控件开发定义的。
//-----------------------------------------------------------------
//EXPORTS
//
//DllGetClassObject PRI ......
这个例子要把bookstore.xml文件增加一条book记录
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="love" ISBN="1234123">
<title>who am i </title>
<author>who</author>
  ......
提高C#编程水平的50个要点
1.总是用属性 (Property) 来代替可访问的数据成员
2.在 readonly 和 const 之间,优先使用 readonly
3.在 as 和 强制类型转换之间,优先使用 as 操作符
4.使用条件属性 (Conditional Attributes ......
命名空间: MapInfo.Data
MapInfo.Data 命名空间包含了实现 MapInfo .NET 数据提供方的类和接口。 对 MapInfo 数据的访问有两种形式:作为使用 SQL 与数据交互的 ADO.NET 数据提供程序和作为使用类与数据交互的 Feature 对象。 MapIn ......