上传.pdf文件以获取链接是这样做的正确方法吗? [英] upload .pdf file for links is this right way to do it?

查看:83
本文介绍了上传.pdf文件以获取链接是这样做的正确方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这种方法无法正常工作,但请先告诉我,这是进行此工作或告诉我如何进行此工作的正确方法.
工作是我想在userend上显示downloadlinks,并从admin用户中为链接添加标题,标题将显示,并且download_link将在单击title时下载.从管理员那里,我想在数据库中存储数据,如上载图和上载文件路径.
请帮助改善代码.

while this not working properly some errors are thier plz suggest me first that is this right way to do this work or tell me how to do this work.
work is that i want to show downloadlinks on userend and from admin user add title for the link which will show and download_link will download on click on title. from admin i want to store data like upload tille and upload file path in database.
plz help to improve code.

try
        {

            SqlCommand cmd = new SqlCommand("insert into tbl_downloads (down_title,down_adddate, down_status ) values ('" + txt_title.Text + "','" + DateTime.Now.ToString() + "',1)", conn);
            int a = 0;
            conn.Open();
            a = cmd.ExecuteNonQuery();
            if (a > 0)
            {
                //data inserted than file shoud be upload thats why get max id first
                string cmd1 = "select max(down_id) from tbl_downloads";
                SqlCommand cmmdfindmaxid = new SqlCommand(cmd1, conn);
                SqlDataReader read = cmmdfindmaxid.ExecuteReader();
                read.Read();
                string id=read["down_id"].ToString();
                //now upload file with name id
                if (fu_upload.HasFile)
                {
                    string extension = Path.GetExtension(fu_upload.PostedFile.FileName);
                    string filepath = "pdf/" + id + extension;
                    fu_upload.SaveAs(filepath);
                    string qryup = "update tbl_downloads set down_path='" + filepath;
                    SqlCommand cmd11 = new SqlCommand(qryup, conn);
                    int aa = 0;
                    aa = cmd11.ExecuteNonQuery();
                    if (aa > 0)
                    {
                        ltrl_msg.Text = "Download File Insert Successfully";
                    }
                }
            }
        }
        catch (Exception ee)
        {
            ltrl_msg.Text = "Error:" + ee.Message;
        }
        finally
        {
            conn.Close();
            pnl_info.Visible = false;
            pnl_edit.Visible = false;
            pnl_del.Visible = false;
            pnl_add.Visible = false;
            fillgvdown();
        }


谢谢
问候
Umesh Daiya


Thanks
Regards
Umesh Daiya

推荐答案

使用以下代码

首先通过解决方案资源管理器将文件夹添加到项目中
用于存储名为pdf的.pdf文件.
Use the following code

First add a folder into project by solution explorer
for storing .pdf files named as pdf.
try
    {

        SqlCommand cmd = new SqlCommand("insert into tbl_downloads (down_title,down_adddate, down_status ) values ('" + txt_title.Text + "','" + DateTime.Now.ToString() + "',1)", conn);
        int a = 0;
        conn.Open();
        a = cmd.ExecuteNonQuery();
        if (a > 0)
        {
            //data inserted than file shoud be upload thats why get max id first
            string cmd1 = "select max(down_id) from tbl_downloads";
            SqlCommand cmmdfindmaxid = new SqlCommand(cmd1, conn);
            SqlDataReader read = cmmdfindmaxid.ExecuteReader();
            read.Read();
            string id=read["down_id"].ToString();
            //now upload file with name id
            if (fu_upload.HasFile)
            {
// for storing .pdf files into pdf folder which is previously added
// into solution explorer.
                fu_upload.SaveAs(Server.MapPath("pdf//") + fu_upload.FileName);
//for retrieving the path of .pdf file.
                string filepath = "~/pdf/"+FileUpload2.FileName+"";
 // now pass this path into database &.
// for downloading, retrieve the same path from database.
                string qryup = "update tbl_downloads set down_path='" + filepath;
                SqlCommand cmd11 = new SqlCommand(qryup, conn);
                int aa = 0;
                aa = cmd11.ExecuteNonQuery();
                if (aa > 0)
                {
                    ltrl_msg.Text = "Download File Insert Successfully";
                }
            }
        }
    }
    catch (Exception ee)
    {
        ltrl_msg.Text = "Error:" + ee.Message;
    }
    finally
    {
        conn.Close();
        pnl_info.Visible = false;
        pnl_edit.Visible = false;
        pnl_del.Visible = false;
        pnl_add.Visible = false;
        fillgvdown();
    }


这篇关于上传.pdf文件以获取链接是这样做的正确方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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