项目开发总结(联想GIS)-----上传附件,动态创建文件夹
来源:互联网 发布:charles破解版for mac 编辑:程序博客网 时间:2024/06/07 03:35
1、根据条件来动态的创建附件上传的文件夹。
要保证目录具有写的权限。
//上传附件
if (this.fulLocation.HasFile)
{
try
{
string FileName = this.fulLocation.FileName;//获取文件名
string[] FileArray = FileName.Split('.');
string FileExt = FileArray[FileArray.Length - 1].ToString();//获取文件后缀
int FileSize = this.fulLocation.PostedFile.ContentLength;//获取文件大小
//生成随机数
Random oRandom = new Random();
string oStringRandom = oRandom.Next(9999).ToString();
//格式化日期作为文件名
long oStringTime = DateTime.Now.ToFileTimeUtc();
//组合成文件名
string PostFile = oStringTime + oStringRandom + "." + FileExt;
//定义部门文件夹(根据dropdownlist动态创建根文件夹)
string rootCategory = this.ddlD.SelectedValue;
//所要创建文件夹的名字(根据dropdownlist的选择项来动态的创建)
string CategoryDirectory = this.ddlCategory.SelectedItem.Text.Replace("-","");
string CategoryPath = Server.MapPath("~") + "//" + rootCategory + "//" + CategoryDirectory;
//如果文件夹不存在则创建
if (!Directory.Exists(CategoryPath))
{
Directory.CreateDirectory(CategoryPath);
}
this.fulLocation.SaveAs(CategoryPath + "//" + PostFile);
doc.Location = "~" + "//" + rootCategory + "//" + CategoryDirectory + "//" + PostFile;
doc.LocationName = FileName;
}
catch (Exception ex)
{
throw ex;
}
}
else
{
doc.Location = "";
}
2。如果执行删除操作,将同时加数据库中的数据和文件夹中的文件删除
//删除文档的同时删除附件
Document doc = ServiceLocator.DocumentService.LoadDocument(id);
string filePath = Server.MapPath(doc.Location);
FileInfo filedel = new FileInfo(filePath);
if (filedel.Exists)
{
filedel.Delete();
}
ServiceLocator.DocumentService.DeleteDocument(id);
JavaScript.Alert("恭喜您!操作成功!", this.Page);
DataBind_Document(1);
return;
- 项目开发总结(联想GIS)-----上传附件,动态创建文件夹
- 项目开发总结(联想GIS)-----发送邮件
- 联想项目开发总结
- 动态上传多附件!!
- 简单总结--JavaWeb开发中的附件上传 不要再混乱!
- 动态多附件上传 多附件动态上传
- 动态多附件上传 多附件动态上传
- GIS项目资料总结
- STRUTS+2+动态上传附件
- fileupload应用 上传数据自己选择收件人选择上传的附件点发送后会创建一个文件夹存入你上传的附件
- 今天工作上传附件总结
- spring boot附件上传总结
- 使用DOM动态创建js实现多附件上传客户端
- 动态添加附件,添加指定文件夹
- 上传文件、创建文件夹
- asp.net 动态添加多附件上传.
- asp.net 动态添加多附件上传
- asp.net 动态添加多附件上传.
- 第一次离职
- PowerDesiner 12 最新下载(测试可下)
- 网游市场形势并非一片大好
- SQL索引全攻略
- 博客新贵掘金互联网 续写网络乌托邦神话
- 项目开发总结(联想GIS)-----上传附件,动态创建文件夹
- 使用ASP.NET Global.asax 文件
- 後一ヶ月の二級試験の書き
- Java正则表达式详解
- 27岁的女性就一定不能转行做开发吗?
- 软件开发中的30个错误
- log4j输出多个自定义日志文件
- sizeof小议
- oracle日维护过程