-
大小: 91KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-05-10
- 语言: C#
- 标签: asp.net,c#
资源简介
c#源码 文件夹上传、修改、删除,文件格式限制,文件大小限制asp.net,适合初学者
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Security;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender EventArgs e)
{
if (!IsPostBack)
{
InitFolderInfo();
InitUploadLimit();
InitFileList();
}
}
protected void ddl_FunctionList_SelectedIndexChanged(object sender EventArgs e)
{
mvFolder.ActiveViewIndex = Convert.ToInt16(ddl_FunctionList.SelectedValue);
}
protected void btn_Upload_Click(object sender EventArgs e)
{
if (FileUpload.HasFile)
{
if (IsAllowableFileType())
{
if (IsAllowableFileSize())
{
string strFileUploadPath = ConfigurationManager.AppSettings[“FileUploadPath“].ToString();
string strFileName = FileUpload.FileName;
string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
FileUpload.SaveAs(strFilePhysicalPath);
lb_FileList.Items.Add(strFileName);
InitFolderInfo();
ShowMessageBox(“文件上传成功“);
}
else
{
ShowMessageBox(“文件大小不符合规定“);
}
}
else
{
ShowMessageBox(“文件类型不符合规定“);
}
}
}
protected void lb_FileList_Selected_indexChanged(object sender EventArgs e)
{
string strFileUploadPath = ConfigurationManager.AppSettings[“FileUploadPath“].ToString();
string strFileName = lb_FileList.SelectedValue;
string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
FileInfo fi = new FileInfo(strFilePhysicalPath);
lab_FileDescription.Text = string.Format(“文件大小:{0}
上传时间:{1}
“ fi.Length fi.CreationTime);
tb_FileNewname.Text = strFileName;
}
private bool IsAllowableFileSize()
{
double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings[“FileSizeLimit“]) * 1024;
if (iFileSizeLimit > FileUpload.PostedFile.ContentLength)
return true;
else
return false;
}
private bool IsAllowableFileType()
{
string strFileTypeLimit = ConfigurationManager.AppSettings[“FileTypeLimit“].ToString();
if (strFileTypeLimit.IndexOf(Path.GetExtension(FileUpload.FileName).ToLower()) > 0)
return true;
else
return false;
}
protected void btn_Download_Click(object sender EventArgs e)
{
string strFileUpload
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3247 2018-03-20 13:27 sharedoc\Default.aspx
文件 7458 2018-03-20 15:03 sharedoc\Default.aspx.cs
文件 829 2018-03-20 13:31 sharedoc\Default2.aspx
文件 693 2018-03-20 13:32 sharedoc\Default2.aspx.cs
文件 1564 2018-03-20 14:34 sharedoc\sharedoc.sln
..A..H. 14336 2018-03-20 15:55 sharedoc\sharedoc.suo
文件 198521 2018-03-28 11:30 sharedoc\Upload英汉词典.txt
文件 735 2018-03-19 21:46 sharedoc\web.config
目录 0 2018-03-20 12:31 sharedoc\Upload
目录 0 2018-03-28 11:30 sharedoc
----------- --------- ---------- ----- ----
227383 10
- 上一篇:WPFGRAPHICS.zip
- 下一篇:c#背单词程序源代码,非常简单
评论
共有 条评论