上传文件保存字节流,下载
来源:互联网 发布:java的后缀名 编辑:程序博客网 时间:2024/05/22 14:19
public ActionResult ExcelUpLoad(HttpPostedFileBase file, string type)
{
string filePath = string.Empty;
var contentType = "";
if (file != null)
{
try
{
Stream stream = null;
stream = file.InputStream;
var fileBinary = new byte[stream.Length];
stream.Read(fileBinary, 0, fileBinary.Length);
contentType = file.ContentType;
TopicexcelFileName = file.FileName;
string fileName = file.FileName;
fileName = fileName.Substring(fileName.LastIndexOf("."));
string StrType = fileName.Split('.')[1];
ViewBag.fileType = StrType;
ViewBag.fileName = file.FileName;
//string fileName_des = Guid.NewGuid().ToString();
//fileName_des = fileName_des + "." + StrType;
string uploadFolder = "/Excel/" + TopicexcelFileName;
// file.SaveAs(Topicexcelfilepath + "/" + TopicexcelFileName);
filePath = uploadFolder;
ViewBag.filePath = filePath;
ViewBag.type = type;
int AttachmentTypeId = 0;
string AttachmentTypeName = "";
if (type == "1")
{
AttachmentTypeId = 1;
AttachmentTypeName = "";
}
if (type == "2")
{
AttachmentTypeId = 2;
AttachmentTypeName = "";
}
var downloadCopy = new Download
{
DownloadGuid = Guid.NewGuid(),
UseDownloadUrl = false,
DownloadBinary = fileBinary,
ContentType = contentType,
Filename = TopicexcelFileName.Substring(0, TopicexcelFileName.LastIndexOf(".")),
Extension = TopicexcelFileName.Substring(TopicexcelFileName.LastIndexOf(".")),
EntityName = "QuoteRecord",
AttachmentTypeId = AttachmentTypeId,
AttachmentTypeName = AttachmentTypeName,
IsNew = true,
DisplayOrder = 0,
CreatedOnUtc = System.DateTime.UtcNow,
UpdatedDateTime = System.DateTime.UtcNow,
IsDeleted = false
};
Insert(downloadCopy);
ViewBag.DownloadId = downloadCopy.Id;
}
catch (Exception ex)
{
ViewBag.fileName = "";
ViewBag.filePath = ex.Message;
}
}
else
{
ViewBag.fileName = "";
ViewBag.filePath = "";
}
return View();
}
{
string filePath = string.Empty;
var contentType = "";
if (file != null)
{
try
{
Stream stream = null;
stream = file.InputStream;
var fileBinary = new byte[stream.Length];
stream.Read(fileBinary, 0, fileBinary.Length);
contentType = file.ContentType;
TopicexcelFileName = file.FileName;
string fileName = file.FileName;
fileName = fileName.Substring(fileName.LastIndexOf("."));
string StrType = fileName.Split('.')[1];
ViewBag.fileType = StrType;
ViewBag.fileName = file.FileName;
//string fileName_des = Guid.NewGuid().ToString();
//fileName_des = fileName_des + "." + StrType;
string uploadFolder = "/Excel/" + TopicexcelFileName;
// file.SaveAs(Topicexcelfilepath + "/" + TopicexcelFileName);
filePath = uploadFolder;
ViewBag.filePath = filePath;
ViewBag.type = type;
int AttachmentTypeId = 0;
string AttachmentTypeName = "";
if (type == "1")
{
AttachmentTypeId = 1;
AttachmentTypeName = "";
}
if (type == "2")
{
AttachmentTypeId = 2;
AttachmentTypeName = "";
}
var downloadCopy = new Download
{
DownloadGuid = Guid.NewGuid(),
UseDownloadUrl = false,
DownloadBinary = fileBinary,
ContentType = contentType,
Filename = TopicexcelFileName.Substring(0, TopicexcelFileName.LastIndexOf(".")),
Extension = TopicexcelFileName.Substring(TopicexcelFileName.LastIndexOf(".")),
EntityName = "QuoteRecord",
AttachmentTypeId = AttachmentTypeId,
AttachmentTypeName = AttachmentTypeName,
IsNew = true,
DisplayOrder = 0,
CreatedOnUtc = System.DateTime.UtcNow,
UpdatedDateTime = System.DateTime.UtcNow,
IsDeleted = false
};
Insert(downloadCopy);
ViewBag.DownloadId = downloadCopy.Id;
}
catch (Exception ex)
{
ViewBag.fileName = "";
ViewBag.filePath = ex.Message;
}
}
else
{
ViewBag.fileName = "";
ViewBag.filePath = "";
}
return View();
}
阅读全文
0 0
- 上传文件保存字节流,下载
- 文件流上传,下载
- 服务器获取字节流并保存文件
- 将文件上传、下载(以二进制流保存到数据库)
- 将文件上传、下载(以二进制流保存到数据库)
- WPF用流的方式上传/显示/下载图片文件(保存在数据库)
- C#将文件上传、下载(以二进制流保存到数据库)
- 上传文件 IE不兼容的问题[提示下载保存]
- LightSwitch文件的上传,下载及保存(数据库版)
- 文件上传和保存
- 上传文件保存数据库
- PHP 上传保存文件
- C# 学习: 读取文件流,保存到字节中
- PHP下载保存文件
- 上传文件 | 下载文件
- Inet1 按字节下载文件!!
- Inet1 按字节下载文件!!
- 20171023_chr_classupload Struts2字节流完成文件上传
- Python学习流程控制 if 语句、while语句、for..in...循环
- arm-linux-gcc 之 stmdb/stmfd/ldmia/ldmfd or push/pop ???
- Java调用C/C++编写的第三方dll动态链接库(非native API)--- JNI
- 【Ray Tracing in One Weekend】(ch8)Metal&Lambertian
- 使用Delphi怎么连接SQL数据库
- 上传文件保存字节流,下载
- hrbust 1401 九连环
- 【技巧】Eclipse ctrl+左键 进入方法
- 光标函数(自己整理的,求指导)
- ubuntu下修改键位
- python中subprocess.Popen执行命令并持续获取返回值
- 《Java编程技巧1001条》358条:控制随机整数的范围
- Java并发之死锁
- jsp中js,css文件相对地址的引用