如何下载附件文件(SQL 2008)? [英] How to download attachment files(sql 2008)?
本文介绍了如何下载附件文件(SQL 2008)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的实际代码
This is my actual code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
byte[] FSize = new byte[FileUpload1.PostedFile.ContentLength + 1];
HttpPostedFile uploadedFile = FileUpload1.PostedFile;
uploadedFile.InputStream.Read(FSize, 0, FileUpload1.PostedFile.ContentLength);
SqlConnection cn = new SqlConnection(@"Data Source=TEKPC26\TEKSP26;Initial Catalog=sample;User ID=sa;Password=tekskills_26");
cn.Open();
string strQuery = "insert into TestTable(FileSize) values(@FileName)";
SqlCommand cmd = new SqlCommand(strQuery, cn);
cmd.Parameters.Add(new SqlParameter("@FileName", FSize));
if (FileUpload1.HasFile)
{
FileUpload1.PostedFile.SaveAs("C:\\Users\\200228" + "\\ + FileUpload1.FileName);
Label2.Text = "uploaded successfully";
}
else
{
Label2.Text = "upload file";
}
cmd.ExecuteNonQuery();
cn.Close();
}
我要上传的数据是数据必须存储在数据库中!
目前可以将文件存储在db中.
同时,该文件我需要放置一个下载链接!!
What I want to uploading the data that data must be stored in database!
At present it''s ok that file is storing in db.
At the same time that file I need to put a Download Link!!
Can any one pls help me!!
推荐答案
必须尝试任何有关标签的专业知识吗?这真的很有用..
试试吧.
就像在html
中一样
have to try any expertise work on label???which is really useful..
try it.
like in html
<asp:label id="Label1" runat="server" text="/<a href='http://www.google.com'>dcdcd</a>" xmlns:asp="#unknown"></asp:label>
对于C#,您可以做..
for c# you can do..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
byte[] FSize = new byte[FileUpload1.PostedFile.ContentLength + 1];
HttpPostedFile uploadedFile = FileUpload1.PostedFile;
uploadedFile.InputStream.Read(FSize, 0, FileUpload1.PostedFile.ContentLength);
SqlConnection cn = new SqlConnection(@"Data Source=TEKPC26\TEKSP26;Initial Catalog=sample;User ID=sa;Password=tekskills_26");
cn.Open();
string strQuery = "insert into TestTable(FileSize) values(@FileName)";
SqlCommand cmd = new SqlCommand(strQuery, cn);
cmd.Parameters.Add(new SqlParameter("@FileName", FSize));
if (FileUpload1.HasFile)
{
FileUpload1.PostedFile.SaveAs("C:\\Users\\200228" + "\\ + FileUpload1.FileName);
Label2.Text = @"uploaded successfully <a href=""+Server.MapPath("C:\\Users\\200228" + "\\ + FileUpload1.FileName")+""></a>";
}
else
{
Label2.Text = "upload file";
}
cmd.ExecuteNonQuery();
cn.Close();
}
这篇关于如何下载附件文件(SQL 2008)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文