Change FileName of Upload and save

12 posts, 1 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 15 Jul 2010 Link to this post

    Hi,

    I'm using AsyncUpload in a RadGrid

     

    <

     

    FormTemplate>.

     

     

     

     

    When the User makes the changes to the record I want to Change the filename when it uploads it. The below works for the first row in the radgrid. When I try to update the second row  I get object reference not set to an instance of an object.

    Am i missing something?

    Thanks

    string filenamenew = string.Empty;
      
              
                GridEditFormItem editedItem = (GridEditFormItem)(gvContractors.MasterTableView.GetItems(GridItemType.EditFormItem)[0]);
                RadTextBox txtcustomername = (RadTextBox)editedItem.FindControl("txtcustomername");
                filenamenew = txtcustomername.Text.Replace(" ", "_");
              
              
            e.File.SaveAs(System.Configuration.ConfigurationManager.AppSettings["ContractorDatabaseUploads"] + filenamenew + "_Certificate" + e.File.GetExtension());

    >

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 16 Jul 2010 Link to this post

    Hi Karl,

    You code looks correct. On which line do you receive the exception. Can you paste here the stack-trace so that we can take a look at it?

    Sincerely yours,
    Genady Sergeev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 19 Jul 2010 Link to this post

    Hi,
    The attached is all I get, I can't view the stacktrace. I have an email function that sends emails when the

     

     

    void Application_Error(object sender, EventArgs e)

     

    {

    }
    is hit, and nothing is fired. This works on everthing else

    Any ideas?

  4. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 22 Jul 2010 Link to this post

    Hi,


    Is this there anything else I can do to get this to work?

    Thanks
  5. T. Tsonev
    Admin
    T. Tsonev avatar
    2830 posts

    Posted 22 Jul 2010 Link to this post

    Hello Karl,

    You can obtain a full stack-trace if you temporarily disable the AJAX updates on the page.

    If you're using RadAjaxManager set EnableAJAX to "false".

    In case you're using update panels set EnablePartialRendering on the ScriptManager to "false":

    <asp:ScriptManager ID="RadScriptManager1" runat="server" EnablePartialRendering="false">
    </asp:ScriptManager>

    We should be able to help with the full stack trace at hand.

    You should also be aware that there's a known issue with the RadAsyncUpload in the official Q2 release. Our recommendation is to update to internal build 2010.2.722 before continuing.

    I hope this helps.

    Greetings,
    Tsvetomir Tsonev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 22 Jul 2010 Link to this post

    Thanks, this is what I get:
     

    Server Error in '/AppTest' Application.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 219:            GridEditFormItem editedItem = (GridEditFormItem)(gvContractors.MasterTableView.GetItems(GridItemType.EditFormItem)[0]);
    Line 220:            RadTextBox txtcustomername = (RadTextBox)editedItem.FindControl("txtcustomername");
    Line 221: filenamenew = txtcustomername.Text.Replace(" ", "_");Line 222:        
    Line 223:        

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Business_Tools_Contractor_Database_Default.RadAsyncUpload1_FileUploaded(Object sender, FileUploadedEventArgs e) in d:\Inetpub\wwwroot\AppTest\Default.aspx.cs:221
       Telerik.Web.UI.RadAsyncUpload.OnFileUploaded(FileUploadedEventArgs e) +75
       Telerik.Web.UI.RadAsyncUpload.RaisePostDataChangedEvent() +214
       Telerik.Web.UI.RadWebControl.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +7
       System.Web.UI.Page.RaiseChangedEvents() +117
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1646
    
  7. Tojara
    Tojara avatar
    7 posts
    Member since:
    Aug 2008

    Posted 23 Jul 2010 Link to this post

    In which event do you access the RadTextBox? I suppose that FindControl returns null instead of RadTextBox hence the exception. Here is an alternative approach:

    void Grid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                string filenamenew = string.Empty;
     
                RadTextBox txtcustomername = (RadTextBox)editedItem.FindControl("txtcustomername");
                filenamenew = txtcustomername.Text.Replace(" ", "_");
     
     
                e.File.SaveAs(System.Configuration.ConfigurationManager.AppSettings["ContractorDatabaseUploads"] + filenamenew + "_Certificate" + e.File.GetExtension());
            }
        }
  8. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 23 Jul 2010 Link to this post

    This is what I have,
    protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        string filenamenew = string.Empty;
          
            GridEditFormItem editedItem = (GridEditFormItem)(gvContractors.MasterTableView.GetItems(GridItemType.EditFormItem)[0]);
            RadTextBox txtcustomername = (RadTextBox)editedItem.FindControl("txtcustomername");
            filenamenew = txtcustomername.Text.Replace(" ", "_");
          
          
        e.File.SaveAs(System.Configuration.ConfigurationManager.AppSettings["ContractorDatabaseUploads"] + filenamenew + "_Certificate" + e.File.GetExtension());
    }

    I tried the way you suggested but  it comes up with e.File does not exist which makes sense as e.File exists on the _FileUploaded Event.

    Thanks
  9. Tojara
    Tojara avatar
    7 posts
    Member since:
    Aug 2008

    Posted 23 Jul 2010 Link to this post

    I believe that this is issue with RadGrid. I am not sure if it is possible to access controls that are in edit form outside of the Grid context.
  10. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 23 Jul 2010 Link to this post

    Any ideas on how I can achieve what I want?
  11. Answer
    Tojara
    Tojara avatar
    7 posts
    Member since:
    Aug 2008

    Posted 23 Jul 2010 Link to this post

    If I were you, I would use the RadAsyncUpload.UploadedFiles collection. You can use it to access the uploaded files outside of the FileUploaded event. First file in the collection is from the first input, second from the second and so on. You can it inside the ItemCommand event of RadGrid.
  12. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 26 Jul 2010 Link to this post

    Thanks, that worked. If any one else is interested :
    used this sample and post for ref :
    http://www.telerik.com/community/forums/aspnet-ajax/upload/radasyncupload-not-to-save-to-file-location.aspx
        IList<UploadedFile> files;
      
        protected void Page_Load(object sender, EventArgs e)
        {
            files = new List<UploadedFile>();
        }
        protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            files.Add(e.File);
        }
      
    //Add this in your Update and Insert
          foreach(UploadedFile test in files)
            {
                test.SaveAs(System.Configuration.ConfigurationManager.AppSettings["MyPath"] + filenamenew + "_Certificate" + test.GetExtension().ToString());
            }
Back to Top