一個簡單的網盤(WebDrive with ASP.NET (C#))

本文介绍了一个使用纯C#编写的ASP.NET应用程序,该应用实现了文件上传、使用XML进行配置管理、控制网站带宽等功能。文章提供了示例代码,并指导如何安装配置演示项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sample Image - WebDrive.jpg

Introduction

This article will present a full ASP.NET web application written in pure C#. You'll see how to upload a file, use XML to store and read configuration, control the bandwidth used by the web site and adjust it to your needs.

Using the code

Debit control code:

minus.gif Collapse
//
//
//prepare data, read the file
data = null;
try
{
System.IO.FileStream fs = File.OpenRead(LocalServerPath + dlfile);
data = new byte[fs.Length];
fs.Read(data,0, data.Length);
fs.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
#region Debit Control
//Debit control
if (wc.SpeedLimit == 0)
{
blocksize = 2048;
}
else
{
blocksize = (wc.SpeedLimit * 100);
}
while(index < data.Length)
{
if (index < data.Length)
{
s.Write(data,index, this.blocksize);
index = index + blocksize;
s.Flush();
Response.Flush();
}
else
{
s.Close();
break;
}
if (wc.SpeedLimit != 0)
{
System.Threading.Thread.Sleep(100);
}
}
#endregion

How to install the demo?

  1. Download the file and unzip it where you want. Modify the 2 XML config files: WebDriveConfig.xml to specify the storage directory and Users.xml to create a login/password (there are 4 users by default).
  2. Right click on the folder where the webdrive is unzipped, click on properties, go to the web share tab, and share it with any alias name (webdrive for example).
  3. Open IIS in Control panel > administrative tools , open the default website, find the web share named webdrive and right click on it > properties, in the virtual directory tab, in front of application name, click on delete and after create, click OK.
  4. Open your web navigator (all navigators are supported because I don't use JScript or DHTML), type: http://localhost/webdrive, type your login / password.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值