如何将上传的文件及其链接存储到数据库中 [英] how to store uploaded file and its link into database

查看:80
本文介绍了如何将上传的文件及其链接存储到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨....



任何人都可以回答......





如何将上传的简历及其链接存储到数据库中,点击该链接我必须查看上传的简历....

Hi....

Can Anyone Answer...


how to store uploaded resume and its link into database by clicking that link i have to view uploaded resume....

推荐答案

\\in aspx page
<asp:fileupload id="f1" runat="server" xmlns:asp="#unknown" />
\\in C# code page
        f1.SaveAs(Request.PhysicalApplicationPath + "/" + a.ToString() + "/" + f1.FileName);
        ss = a + "/" + f1.FileName;



我的编码.....



my coding.....

protected void b1_Click(object sender, EventArgs e)
   {
       a = drop1.SelectedValue.ToString() + drop2.SelectedValue.ToString();
       // Response.Write(a.ToString());
       f1.SaveAs(Request.PhysicalApplicationPath + "/" + a.ToString() + "/" + f1.FileName);
       ss = a + "/" + f1.FileName;
       _con.Open();
       SqlCommand _cmd = _con.CreateCommand();
       _cmd.CommandType = CommandType.StoredProcedure;
       _cmd.CommandText = "adminupload";
       _cmd.Parameters.Add("@stream", SqlDbType.VarChar).Value = drop1.SelectedItem.ToString();
       _cmd.Parameters.Add("@sem", SqlDbType.VarChar).Value = drop2.SelectedItem.ToString();
       _cmd.Parameters.Add("@subject", SqlDbType.VarChar).Value = TextBox3.Text;
       _cmd.Parameters.Add("@path", SqlDbType.VarChar).Value = ss.ToString();
       _cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = DropDownList1.SelectedItem.ToString();
       _cmd.Parameters.Add("@filename", SqlDbType.VarChar).Value = f1.FileName.ToString();
       _cmd.Parameters.Add("@auther", SqlDbType.VarChar).Value = txtaut.ToString();

       _cmd.ExecuteNonQuery();
       _con.Close();


       _con.Open();
       SqlCommand _cmd1 = _con.CreateCommand();
       _cmd1.CommandType = CommandType.Text;
       _cmd1.CommandText = "select email from clientregi";
       _cmd1.ExecuteNonQuery();
       DataTable dt = new DataTable();
       SqlDataAdapter da = new SqlDataAdapter(_cmd1);
       da.Fill(dt);

    //   SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    //   smtp.EnableSsl = true;
    //   smtp.UseDefaultCredentials = false;
    //   smtp.Credentials = new NetworkCredential("amit.andipara@gmail.com", "81181981");

       foreach (DataRow _dr in dt.Rows)
       {

           //(from,to,subject,body)
         //  MailMessage mail = new MailMessage("amit.andipara@gmail.com", _dr["email"].ToString(), "noble computer", "new materials updated");
        // smtp.Send(mail);
       }
       _con.Close();

       Response.Redirect("uploadfile.aspx");




   }



\\ aspx page ...


\\in aspx page...

<center>
        <table border="2">
            <tr>
                <td style="height: 26px">
                    Enter stream
                </td>
                <td style="height: 26px">
                    <asp:DropDownList ID="drop1" runat="server" Width="129px">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>bca</asp:ListItem>
                        <asp:ListItem>BSC.IT</asp:ListItem>
                        <asp:ListItem>mca</asp:ListItem>
                         <asp:ListItem>M.SC(IT &amp; CA)</asp:ListItem>
                         <asp:ListItem>P.G.D.C.A</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td>
                    Enter sem</td>
                <td>
                    <asp:DropDownList ID="drop2" runat="server" Width="129px">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                        <asp:ListItem>4</asp:ListItem>
                        <asp:ListItem>5</asp:ListItem>
                        <asp:ListItem>6</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td>
                    Enter subject name</td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server" Width="129px"></asp:TextBox></td>
            </tr>
            <tr>
                <td>
                    Enter path</td>
                <td>
                    <asp:FileUpload ID="f1" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    Enter file type</td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server" Width="129px">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>doc</asp:ListItem>
                        <asp:ListItem>pdf</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td>
                    Enter Auther Name</td>
                <td>
                    <asp:TextBox ID="txtaut" runat="server" Width="129px"></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2">
                    <center>
                        <asp:Button ID="b1" runat="server" Text="save" OnClick="b1_Click" Width="87px" /></center>
                </td>
            </tr>
        </table>
    </center>








$ b $只需复制此代码即可试用....我知道它'解决你的问题





u just copy this code and just try it....i thik it' solve your problem


在这个例子中,我假设您正在使用页面上的FileUpload按钮。该代码考虑到用户可以上传与已存在的文档同名的文档。
In this sample, I'm assuming that you are using a FileUpload button on the page. The code takes into account the fact that the user could upload a document with the same name as one that already exists.
private void StoreUploadedFile()
{
  if (!fileUpload.HasFile)
  {
    return;
  }
  string path = Server.MapPath(string.Format("~/Resumes/{0}", Guid.NewGUID()));
  fileUpload.SaveAs(path);

  // Now, save these values to the database
  if (!SaveFileInformation(fileUpload.FileName, path))
  {
    // If we didn't save the file to the database, we have no link - so get rid
    // of the record and inform the user.
    File.Delete(path);
  }
}

我没有包含将文件保存到数据库的代码 - 我假设你知道如何自己编写代码。有几点需要注意;您需要存储原始文件名以及修改后的文件名的路径。其次,如果您没有成功写入数据库,则应删除上载的文件。最后,此代码依赖于您具有写入Resumes目录的适当权限。



我提供的示例没有内置错误处理。您应该考虑将其添加到代码中。我提供的是我在CP编辑器中敲定的样本;它不是生产就绪代码。

I haven't included the code to save the file to the database - I'm assuming you know how to write that code yourself. There are a few things to note; you need to store the original filename, along with the path to the modified filename. Secondly, if you don't succeed in writing to the database, you should remove the file that was uploaded. Finally, this code relies on you having the appopriate privileges to write to the Resumes directory.

The sample I have provided has no error handling built into it. You should consider adding this to the code. What I have provided is a sample that I knocked up in the CP editor; it is not production ready code.


这篇关于如何将上传的文件及其链接存储到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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