Accessing file properties from RadAsyncUpload

Thread is closed for posting
2 posts, 0 answers
  1. Nicky
    Nicky avatar
    2 posts
    Member since:
    Sep 2012

    Posted 25 Sep 2012 Link to this post

    Hi,

    I have a radGrid which uses automatic insert, update and delete and I use a form template to edit a row.  In the edit form, I have one RadAsyncUpload which I use to allow the user to select PDF's from their local machine.  The control works as it should (i.e. it loads the files into the temp folder and then moves them to the target folder when the update or insert commands are fired.

    The problem I am having is I need to be able to grab the filenames and populate a table in a database once the files have been uploaded with these filenames.  I only need the filename, not the complete path on the server.

    I am using a sqldatasource which uses a stored procedure to do the insert/update to the table.  The sqldatasource accepts a filename parameter which is used by the stored proc.

    What I would like to know is:

    • How do I get the filename property for each file uploaded?
    • How would I pass the filenames to the sqldatasource parameter so that each filename can be inserted into the table? (i am unsure as to how multiple filenames can be passed to the stored procedure, when it is only really called once - i.e. when the update button is clicked.  I thought I may have to pass the filenames into the parameter as an array or something, or as csv list and handle this in the sql code, but I'm just guessing at this.)

    I have tried a lot of different things and looked at various posts, but none of them seem to be helping me with this problem.

    I really need to get this working and am getting very frustrated with it.  Any help would be much appreciated.

    Thanks
  2. Nicky
    Nicky avatar
    2 posts
    Member since:
    Sep 2012

    Posted 26 Sep 2012 Link to this post

    I managed to figure this out.  So for anyone that's having the same issue I've pasted the code below.  It's by no means the finished article as I still need to add exception handling etc and remove some of the stuff that's commented out.  This was very quick code just to get it working - but you will see the fundamentals of it.  I ended up not using the sqldatasource and just created the sql command in code behind instead.  You could just as easily use LINQ, which would be a bit neater.

    protected void radGridLogs_UpdateCommand(object sender, GridCommandEventArgs e)
            {
                string filename;
                RadAsyncUpload asl = e.Item.FindControl("RadAsyncUpload1") as RadAsyncUpload;
                TextBox txtLogRef = e.Item.FindControl("log_ref_numberTextBox") as TextBox;
     
                if (asl != null)
                {
                    if (asl.UploadedFiles.Count > 0)
                    {
                        SqlConnection con = new SqlConnection(cs);
                            using (con)
                            {
                                currentUploader = asl;
     
                                foreach (UploadedFile file in asl.UploadedFiles)
                                {
                                    //Response.Write(asl.UploadedFiles[0].FileName);
                                    filename = file.FileName;
                                    //Response.Write(filename);
                                    //Response.Write(txtLogRef.Text);
     
                                    SqlCommand command = new SqlCommand("SP_newDoc", con);
                                    command.CommandType = CommandType.StoredProcedure;
     
                                    command.Parameters.AddWithValue("doc_title", filename);
                                    command.Parameters.AddWithValue("log_ref_number", txtLogRef.Text);
     
     
                                    // open the connection, execute the query, close and dispose
                                    command.Connection.Open();
                                    command.ExecuteScalar();
                                    command.Connection.Close();
                                    command.Dispose();
                                }
     
                            }
                            //lp.Text = asl.UploadedFiles[0].FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top