Treeview item has a problem in Download File

4 posts, 0 answers
  1. HananJ
    HananJ avatar
    15 posts
    Member since:
    Nov 2010

    Posted 28 Nov 2010 Link to this post

    Hello,
    Actually, I have some problem with the Treeview item in particular onClientContextMenuItemClicking as shown below:

    function
     onClientContextMenuItemClicking(sender, args)
    {
            var menuItem = args.get_menuItem();
            var node = args.get_node();
            menuItem.get_menu().hide();
     
            switch (menuItem.get_value()) {
                case "SaveAs":
                    Xlate.Web.Translation.service.ResourceFilesService.ExportResourceFile('108', PassServiceHandler, FailServiceHandler);
                    break;
            }
        }
    Save As menu item is supposed to save resx file [RESOURCE FILE in DOTNET]; it calls a webs service to get the file from the DB, and Download the file, but the below code didn't work out in this case, but when i tried it out without Ajax or Telerick controls, I could work it out:


    [WebMethod()]
            public void ExportResourceFile(string fileId)
            {
                List<ISearchResult> searchResults;
                SearchCriteria searchCriteria;
                try
                {
                        searchCriteria = new SearchCriteria();
                        searchCriteria.ResourceFileID = int.Parse(fileId);
                        searchCriteria.SearchOption = SearchType.ResxKey;
                        
                        ResourceFile resourceFile = ResxFileManager.CreateResourceFile(searchCriteria);
     
                        MemoryStream memoryStream = new MemoryStream();
                        memoryStream = Manager.GenerateResxSourceCode(resourceFile);
                        memoryStream.Position = 0;
                        DownloadFile(memoryStream,resourceFile.Name);
                 }
                 catch (Exception ex)
                 {
                     // set exception message              
                    string errorMessage = String.Format("Failed to export resource fileid ={0}, error:{1}", fileId ,ex.Message);
     
                    // trace call
                    TraceUtil.Write("ResourceFilesService::ExportResourceFile", "Exception occured [{0}]", errorMessage);
     
                    // publish and rethrow the exception
                    BusinessException businessExc = new BusinessException(errorMessage, ex);
                    throw (businessExc);
                 }
              }
     
            private void DownloadFile(MemoryStream memoryStream,string fileName)
            {
                byte[] byteArray = memoryStream.ToArray();
                memoryStream.Flush();
                memoryStream.Close();
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=test.resx");
                HttpContext.Current.Response.AddHeader("Content-Length", byteArray.Length.ToString());
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.BinaryWrite(byteArray);
     
            }


    DownloadFile method should force the Browser to open Save Dialog File, is there anything wrong with the code above, Could you please Help.

    Regards,
    Hanan




    function onClientContextMenuItemClicking(sender, args) {
      
    function onClientContextMenuItemClicking(sender, args) {
            var menuItem = args.get_menuItem();
            var node = args.get_node();
            menuItem.get_menu().hide();
     
            switch (menuItem.get_value()) {
                case "SaveAs":
                    Xlate.Web.Translation.service.ResourceFilesService.ExportResourceFile('108', PassServiceHandler, FailServiceHandler);
                    break;
            }
        }
         var menuItem = args.get_menuItem();
            var node = args.get_node();
            menuItem.get_menu().hide();

            switch (menuItem.get_value()) {
                case "Ssada





    Sdfsefsqweq
    function onClientContextMenuItemClicking(sender, args) {
            var menuItem = args.get_menuItem();
            var node = args.get_node();
            menuItem.get_menu().hide();
     
            switch (menuItem.get_value()) {
                case "SaveAs":
                    Xlate.Web.Translation.service.ResourceFilesService.ExportResourceFile('108', PassServiceHandler, FailServiceHandler);
                    break;
            }
        }
    function onClientContextMenuItemClicking(sender, args) {
            var menuItem = args.get_menuItem();
            var node = args.get_node();
            menuItem.get_menu().hide();
     
            switch (menuItem.get_value()) {
                case "SaveAs":
                    Xlate.Web.Translation.service.ResourceFilesService.ExportResourceFile('108', PassServiceHandler, FailServiceHandler);
                    break;
            }
        }
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 29 Nov 2010 Link to this post

    Hi Hanan,

    I would suggest you to refer to the following help topic which elaborates on downloading files with Ajax.
    I hope it helps.

    Sincerely yours,
    Maria Ilieva
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. HananJ
    HananJ avatar
    15 posts
    Member since:
    Nov 2010

    Posted 12 Dec 2010 Link to this post

    Thanks for reply,
    But my case that I do read the file from the Database, it has no path on the server to download it from, No href , No URL...

    I tried binary.write but apparently it has some many problems with ajax panels, telerik controls, I don't now actually.!
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 15 Dec 2010 Link to this post

    Hi Hanan,

    Could you please try to run your scenario in asp UpdatePanel instead of using RadAjax? Let me know what the result of this test is?


    Greetings,
    Maria Ilieva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top