none
How can ReportViewer Control handle xls and txt files RRS feed

  • Question

  • Hi,

    I'm currently able to upload xls and txt file to my SSRS 2005 Reporting Interface. After hosting, when I click such file(s) using the SSRS Report Manager (Web Interface) I get a popup asking me to Download the file. For the normal rdl files they just open in the interface (as expected).

     

    Now, I have developed a central Web Application, that give the users access to view their reports through this interface and not through SSRS Report Manager. I don't want the end users to use the SSRS Report Manager. This application (that I created) uses ReportViewer Control 2.0 to render reports. When I click regular rdl reports, they opening inline in the control as expected, but the excel and txt files are giving the following error.

    The operation you are attempting on item is not allowed for this item type. (rsWrongItemType) 

    How can I enable my web application to behave in the same manner as the SSRS Report Manager i.e. it should give my the popup with the option to download excel and txt files.

     

    Thanks for the help!

    Regards,

    Thursday, October 7, 2010 7:18 PM

All replies

  • This link might have what you're looking for: http://support.microsoft.com/kb/260519.

    The ReportViewer control should only be used for RDL (remote mode) and RDLC (local mode) files.


    Cephas Lin This posting is provided "AS IS" with no warranties.
    Thursday, October 7, 2010 9:46 PM
    Moderator
  • Thanks for the link.

     

    I worked on this a little bit and I was able to use the details in the article above to invoke a "File Download" box for a sample file in my wep app using:

     

    string filepath = Server.MapPath("~/Images/Logo.gif");

     

    FileInfo file = new FileInfo(filepath);

     

    if (file.Exists)

     

    {

     

    Response.ClearContent();

     

    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

     

    Response.AddHeader("Content-Length", file.Length.ToString());

     

    Response.ContentType = MimeTypeManager.GetResourceContentType(file.Extension.ToLower());

     

    Response.TransmitFile(file.FullName);

     

    Response.End();

     

    }

     

    But what I actually want to achieve is to somehow get this file from the SSRS Report Manager. This is because the required file is hosted on the SSRS 2005 Report Server and I need to give the users the option to save a file once they click the link in my app (similar to the way Report Manager gives). I don't think the files are on a physical path in the Reporting Server but rather in the Reporting Server database. Correct if this is wrong.

     

    Thanks!

    Friday, October 8, 2010 8:57 PM
  • It sounds like what you want to do is open/save xls and txt resources that are published in the Report Server DB. If that is the case you will have use the Reporting Services SOAP endpoints to get the resources you want. The ReportViewer control is only used for viewing reports it won't handle any other file types that are published to a report server. I believe the following API is what you are looking for:

    http://msdn.microsoft.com/en-us/library/reportservice2005.reportingservice2005.getresourcecontents.aspx

    Matt M 
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties

    Saturday, October 9, 2010 12:08 AM
  • I was able to get the required resource from the SSRS Reporting WEb Service API. The following code might be helpful for anyone trying this out.

     

            private void GetResource(int resourceType)

            {

                string contentMimeType = null;

                string contentURL;

     

                // Get the path of the required resource

                contentURL = GetResourcePath(resourceType) + ResourceManager.Resource[resourceType.ToString()];

     

                //Get the required resource details

                CatalogItem item = GetItem(contentURL);

     

                ReportingService rs = new ReportingService();

                rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

     

                // Get the resource content

                Byte[] b = rs.GetResourceContents(contentURL, out contentMimeType);

     

                // Clear the content of the response

                Response.ClearContent();

     

                // Add the file name and attachment, which will force the open/cancel/save dialog to show, to the header

                Response.AddHeader("Content-Disposition", "attachment; filename=" + item.Name);

     

                // Add the file size into the response header

                Response.AddHeader("Content-Length", item.Size.ToString());

     

                // Set the ContentType

                Response.ContentType = item.MimeType;

     

                // Write the file into the response

                Response.BinaryWrite(b);

     

                // End the response

                Response.End();

            }


            private string GetResourcePath(int resourceType)
            { 
                string resourcePath = "";

                switch (resourceType)
                {
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                        resourcePath = PathManager.Path_4;
                        break;
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                        resourcePath = PathManager.Path_3;
                        break;
                    default:
                        Response.Redirect(Constant.CONST_STR_SITE_MAP_PAGE_NAME);
                        break;
                }

                return resourcePath;
            }


    The static classes "ResourceManager" and "PathManager" contains the key/value pair of the report's name and the paths listed in the web.config file. Rest of it seems to be self explaning.

    Thanks!

    Monday, October 18, 2010 6:20 PM