简体   繁体   中英

How to Update Database Table after AjaxFileUpload ASP.NET

The file is uploading to the corresponding path but table (fileinfo) is not updating.. How to achieve the table updation after a file is being uploaded to the server

 protected void UploadComplete(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
 {
    string str = RadioButton1.Text;
    string path = Server.MapPath("~/" + str +"/") + e.FileName;
    AjaxFileUpload1.SaveAs(path);
    SqlConnection con = new SqlConnection("Data Source=localhost\\sqlexpress; Initial Catalog=example;user ID=sa;password=*******;");
    con.Open();        
    string command1 = "insert into fileinfo(fileid,filename,date1) values(@fileid,@filename,@date1)";
    SqlCommand command = new SqlCommand(command1, con);
    command.Parameters.AddWithValue("@fileid", "101");
    command.Parameters.AddWithValue("@filename", e.FileName);
    command.Parameters.AddWithValue("@date1", DateTime.Now);
    command.ExecuteNonQuery();
 }

You can retreive all the files stored in the folder str, you can take array also to store, i have used the string jst to show you, that how you can get all the files from the folder

string getfile="";
foeach(string f in Directory.GetFiles(Server.MapPath("~/"+str+"/"))
{
  getfiles= getfiles + f + ",";
 }

Now You can store the getfiles in your database, I hope it will help you out

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