This is a migrated thread and some comments may be shown as answers.

Change FileName of Upload and save

11 Answers 392 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 15 Jul 2010, 03:52 PM

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());

>

11 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 16 Jul 2010, 04:00 PM
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
0
Karl
Top achievements
Rank 1
answered on 19 Jul 2010, 11:42 AM

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?

0
Karl
Top achievements
Rank 1
answered on 22 Jul 2010, 08:13 AM
Hi,


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

Thanks
0
T. Tsonev
Telerik team
answered on 22 Jul 2010, 02:01 PM
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
0
Karl
Top achievements
Rank 1
answered on 22 Jul 2010, 02:59 PM
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
0
Tojara
Top achievements
Rank 1
answered on 23 Jul 2010, 08:36 AM
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());
        }
    }
0
Karl
Top achievements
Rank 1
answered on 23 Jul 2010, 09:05 AM
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
0
Tojara
Top achievements
Rank 1
answered on 23 Jul 2010, 10:23 AM
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.
0
Karl
Top achievements
Rank 1
answered on 23 Jul 2010, 01:17 PM
Any ideas on how I can achieve what I want?
0
Accepted
Tojara
Top achievements
Rank 1
answered on 23 Jul 2010, 02:18 PM
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.
0
Karl
Top achievements
Rank 1
answered on 26 Jul 2010, 01:29 PM
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());
        }
Tags
AsyncUpload
Asked by
Karl
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Karl
Top achievements
Rank 1
T. Tsonev
Telerik team
Tojara
Top achievements
Rank 1
Share this question
or