【发布时间】:2013-12-30 06:04:11
【问题描述】:
我在我的应用程序中使用引导程序。我在 sql db 中存储了一个 excel 文件。
这是我的代码;
Default.aspx
<div class="control-group">
<label class="control-label">
Upload</label>
<div class="controls">
<input id="fileupload" type="file" runat="server"/>
</div>
</div>
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" />
Default.aspx.cs
protected void btnSave_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("~/Upload/");
HttpFileCollection hfc = Request.Files;
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
if (hfc.Count != 0)
{
string contenttype = String.Empty;
HttpPostedFile hpf = hfc[i];
string fileExtn = Path.GetExtension(hfc[i].FileName).ToLower();
if (fileExtn == ".xls" || fileExtn == ".xlsx" || fileExtn == ".xlmx")
{
switch (fileExtn)
{
case ".xls":
contenttype = "application/excel";
break;
case ".xlsx":
contenttype = "application/excel";
break;
case ".xlmx":
contenttype = "application/excel";
break;
}
if (hpf.ContentLength > 0)
{
string SPfilePath = Server.MapPath("~/Upload/");
string filepath = SPfilePath + System.IO.Path.GetFileName(hpf.FileName);
hpf.SaveAs(filepath);
string ContentType = hpf.ContentType;
int fileLen = hpf.ContentLength;
byte[] fileBytes = new byte[fileLen - 1];
hpf.InputStream.Read(fileBytes, 0, fileBytes.Length);
byte[] Data = fileBytes;
}
new DefaultManager().SaveFile(Data , fileLen ,filepath ,ContentType );
}
}
UploadMsg = auditmgr.AddClientAuditReport(, audit);
}
}
这里我将ContentType 保存为varchar(256),filepath 为varchar(256),fileLen 为int,Data 为varchar(max) 在db 中。它被添加到数据库中。但我不知道如何从 db 检索该 excel 文件。
我在 SQL db 中以字节为单位存储该 excel 文件
【问题讨论】:
标签: c# mysql sql sql-server excel