简体   繁体   中英

problem in aspx c# rename file before upload and save to name with database

I have problem in upload file with aspx c# sql server

After downloading the file, it is saved with the name of the address from the textbox, but in the database it takes the old name of the file. For example, you entered the address of the file in the textbox, which is report, and the file name before downloading is (file.mp4) when you upload it, it is changed to report.mp4 to the path C:\\Downloads and the file is saved with this name report.mp4 in the folder, but in the database the file is saved with the original name, which is file.mp4 I want to solve this problem, please help me

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;

namespace System_ALsmood_data.admin

{ 
    public partial class add_vedio : System.Web.UI.Page
    {
        myFunctions func = new myFunctions();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                showUnits();
                showCategory();
                showBranches();


            }
        }


        protected void lnkSave_Click(object sender, EventArgs e)
        {
            string sql = @"INSERT INTO addProduct
           ([product_Name]
           ,[product_upDefault]
           ,[product_upreport]
           ,[product_upfile]        
           ,[date_added])
     VALUES 
 (N'{0}',N'{1}',N'{2}',N'{3}',N'{4}'";

            string date = "Cast(Convert(varchar,getdate(),101) as Datetime)";
            Users user = new Users();
            string user_id = user.sessionUser();
            string folderPath = Server.MapPath("/Upload/upproduct/up-product/");
            string folderPath2 = Server.MapPath("/Upload/upproduct/up-report/");
            string folderPath3 = Server.MapPath("/Upload/upproduct/up-file/");
            //dddd

           
            //ddddd
            string sql_insert = string.Format(sql,
                txt_nameVedio.Text, 
                FileUploadVedio.FileName,
                FileUploadReport.FileName,
                FileUploadOther.FileName,               
                date);
            
            func.fireSql(sql_insert);

            Labmsg.Text = "Uploaded successfully";
            Labmsg.ForeColor = ColorTranslator.FromHtml("#037203");
            Session["UseIsAuthenticated"] = "true";

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "redirectJS",
            "setTimeout(function() { window.location.replace('home.aspx') }, 5000);", true);



            if (this.FileUploadVedio.HasFile && !string.IsNullOrEmpty(this.txt_nameVedio.Text))
            {
                string ext = System.IO.Path.GetExtension(FileUploadVedio.PostedFile.FileName);
                this.FileUploadVedio.PostedFile.SaveAs(Server.MapPath("~/Upload/upproduct/up-product/") + this.txt_nameVedio.Text + ext);
            }

 if (this.FileUploadReport.HasFile && !string.IsNullOrEmpty(this.txt_nameVedio.Text))
            {
                string ext = System.IO.Path.GetExtension(FileUploadReport.PostedFile.FileName);
                this.FileUploadReport.PostedFile.SaveAs(Server.MapPath("~/Upload/upproduct/up-product/") + this.txt_nameVedio.Text + ext);
            }
            
             if (this.FileUploadOther.HasFile && !string.IsNullOrEmpty(this.txt_nameVedio.Text))
            {
                string ext = System.IO.Path.GetExtension(FileUploadOther.PostedFile.FileName);
                this.FileUploadOther.PostedFile.SaveAs(Server.MapPath("~/Upload/upproduct/up-product/") + this.txt_nameVedio.Text + ext);
            }
            


        }
    }
}

I mean When uploading a file, it saves the file in the specified path, but the file name is not saved in the database

I took some pictures to explain the problem

enter image description here

enter image description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM