关于文件上传 [英] Regarding file upload

查看:68
本文介绍了关于文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用asp.net?

解决方案

中的文件上传工具将pdf文件保存在数据库中。网上有很多样本。首先使用FileUpload控件。实现File_Uploaded事件并在那里将文件保存到您需要的任何位置。


这段代码非常有助于您将pdf文件保存在数据库中:



string path =;

protected void Page_Load(object sender,EventArgs e)

{



}



protected void btnUpload_Click(object sender,EventArgs e)

{

if( FileUpload1.HasFile)

{

string filename = FileUpload1.FileName;

path =〜// Files //+ filename; < br $>


FileUpload1.SaveAs(Server.MapPath(路径));

}

}

protected void btnSave_Click(object sender,EventArgs e)

{

SqlConnection cnn = new SqlConnection(Data Source = hoth; Initial Catalog = Chintan; User ID = sa);

cnn.Open();

SqlCommand cmd = new SqlCommand(插入到tblFiles值(@ filename,@ file));

cmd.Parameters.AddWithValue(filename,txtfilename.text);

cmd。 Parameters.AddWithValue(file,path);

cmd.ExecuteNonQuery();

cnn.Close();

}

How to save pdf file in database using file upload tool in asp.net?

解决方案

There are many samples online. First use the FileUpload control. Implement the File_Uploaded event and in there save the file wherever you need.


This code very help full to you to save pdf file in database:

string path = "";
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
path = "~//Files//" + filename;

FileUpload1.SaveAs(Server.MapPath(path));
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection("Data Source=hoth;Initial Catalog=Chintan;User ID=sa");
cnn.Open();
SqlCommand cmd = new SqlCommand("Insert into tblFiles values(@filename,@file)");
cmd.Parameters.AddWithValue("filename", txtfilename.text);
cmd.Parameters.AddWithValue("file", path);
cmd.ExecuteNonQuery();
cnn.Close();
}


这篇关于关于文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆