如何上传和检索简历? [英] How to upload and retrieve a Resume?

查看:62
本文介绍了如何上传和检索简历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在UI上有一个上传控件,保存和检索按钮.
我想要的是,当我单击保存时,文件应该保存在数据库中,而当我单击检索"时,应该从我的计算机中检索该履历.
我应该怎么办?我已编写代码:

Hi,

I have an upload control, save ,and retrive button on the UI.
What I want is when I click on to the save, file should be saved in the database and when I click on retrive then that resume should be retrieved from my computer.
What should I do? I have written code:

int a = 2;
       Byte[] bye = null;
       // Byte img =Convert.ToByte(FileUpload1.PostedFile);
       HttpPostedFile file = FileUpload1.PostedFile;
       bye = new Byte[file.ContentLength];
       file.InputStream.Read(bye, 0, file.ContentLength);

       string cn = "Data Source=hcl;Initial Catalog=mydata;Integrated Security=True";
       SqlConnection con = new SqlConnection(cn);
       SqlCommand cmd = new SqlCommand("insert into upload values(@a,@bye)", con);
       con.Open();
       cmd.CommandType = CommandType.Text;
       cmd.Parameters.Add(new SqlParameter("@a", a));
       cmd.Parameters.Add(new SqlParameter("@bye", bye));
       cmd.ExecuteNonQuery();
       con.Close();


我应该在数据库中使用哪种数据类型?我已将varchar(50)用作电子邮件.我应该使用哪种数据类型进行恢复?我上面的代码也可以吗?


What datatype should I use in database? I have used as varchar(50) for email. What datatype should I use for resume? Also will my above code work? And how will I able to retrive it back?

推荐答案

使用varbinary(MAX)作为数据类型来存储简历.您要存储在数据库中的另一件事是要上传的简历的文件类型,以便在下载并显示给用户时可以通知用户文件类型并为Response.ContentType提供适当的内容类型.

将文件存储在数据库中的另一种方法是将其存储在服务器上的某个目录中,并将文件位置保存在数据库表中.我选择此解决方案是因为在数据库中存储和检索pdf文件时遇到了很多问题.当我将pdf文件存储为varbinary(MAX)并在以后检索它并将其呈现给用户时,大多数情况下pdf文件都会损坏.这只是我的经验,我希望您能避免破坏文件的麻烦.
Use varbinary(MAX) as datatype to store resume. Another thing that you want to store in database is file type of resume you are uploading so that when you download it and show it to the user you can inform user about file type and provide proper content type for Response.ContentType .

Alternative to storing file in database is to store it in some directory on the server and save the file location in the database table. I opted for this solution because I had a lot of issues storing and retrieving pdf files in database. Most of the time pdf files get corrupted when I stored it as a varbinary(MAX) in database and later retrieve it and present it to user. This is just my experience I am sharing so that u can avoid frustration of file being corrupted.


通过输入关键字"使用Csharp将二进制数据存储到Sql中 ",我在Google中找到了,

http://www.dbtutorials.com/advanced/storing-binary-sql-cs.aspx [^ ]

这正是我想您要的,

如果有帮助,请 投票 接受答案 .
By entering key word ''Storing binary data to Sql with Csharp'' in google I found,

http://www.dbtutorials.com/advanced/storing-binary-sql-cs.aspx[^]

This is exactly I think you want,

Please vote and Accept Answer if it Helped.


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

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