Read XSL file from Web Service

Posted on 2006-04-11
Last Modified: 2012-05-05
Hi Experts,

I have a C# application that does a lot reporting. These reports are web based and formatted using XSL files located on the local drive. A config file with key-value settings is used to store the path of the location of theses 3 files.
For example:
Key="FileOne" Value="H:\formatting\stylesheet\file1.xsl"
Key="FileTwo" Value="H:\formatting\stylesheet\file3.xsl"
Key="FileThree" Value="H:\formatting\stylesheet\file3.xsl"

Everything is working fine as it is. However theses 3 XSL files now need to be shared corporately. And we came up with the use of a web service.

I know basic how to create a web service using Visual Studio 05 - However I need to know if it possible to "dump" these files into a web service  and have their configuration value point to the URL - if it's possible - then how would I implement it?

Question by:yaney00074
    LVL 5

    Expert Comment

    It is surely possible to do this via a web service. However, I think this would be overkill because (i) it's only a one-way communication from server to client and (ii) the information on the server is static.
    Just put the XSL files on your intranet server and use the WebRequest class to fetch it. In the config file you need the URL of the XSL files instead of local file paths and names.
    The following is a code snippet from the online help of Visual Studio 05 illustrating the straight forward use of the WebRequest class:

                ' Create a request for the URL.        
                Dim request As WebRequest = WebRequest.Create("")
                ' If required by the server, set the credentials.
                request.Credentials = CredentialCache.DefaultCredentials
                ' Get the response.
                Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
                ' Display the status.
                ' Get the stream containing content returned by the server.
                Dim dataStream As Stream = response.GetResponseStream()
                ' Open the stream using a StreamReader for easy access.
                Dim reader As New StreamReader(dataStream)
                ' Read the content.
                Dim responseFromServer As String = reader.ReadToEnd()
                ' Display the content.
                ' Cleanup the streams and the response.

    Author Comment

    thanx for the feedback

    However it's little too complicaed to implement. I need a quick fix.
    Let's drop the web service thing if there's a potential problem.

    How would I use it with a website?
    LVL 5

    Accepted Solution

    As I see it, the wesite is approach *is* the quickest and most uncomplicated fix. Web service brings much more implementation overhead.

    > However it's little too complicaed to implement.
    I don't quite understand you. The above code snippet contains 11 lines of code. This is too complicated? What did you expect?
    A web service involves a running script/ at server side handling the request. Although VS05 has great support for web services this is more complicated than inserting 11 lines of code :)
    And be aware, using a web service you will get a string or stream as return output. Just the same as with WebRequest.

    > How would I use it with a website?
    Well, that depends very much on how you used the local file up to now. Do you open a StreamReader, use a string, or just feed the filename to a black box?
    Do you use XslCompiledTransform or XmlReader?

    What to do:
    1) Put the XSL files on your web server, e.g. at
    2) Fetch it from the web
          WebRequest req = WebRequest.Create("");
          HttpWebResponse webRes = (HttpWebResponse) req.GetResponse();
    3) Initialize a stream reader with the content of file1.xsl
          StreamReader resStream = new StreamReader(webRes.GetResponseStream());
    4) Use the stream reader directly,
        or read it to a string for further use
          string resString = resStream.ReadToEnd();
        or use the stream to create a XmlReader
          XmlReader xmlReader = XmlReader.Create(resStream)
        or load the XSL definition into a XslCompiledTransform object
        or write it to a temporary file (if you require a local file for further processing)
          StreamWriter tempStream = new StreamWriter("H:\temp\rand_id.xsl");
    5) close resources

    If you are using a XslCompiledTransform object, you might get away without any of the above stuff. Just look at the VS05 help for XslCompiledTransform.Load(String). As parameter you can specify an URI to the XSL file. Thus,
       XslCompiledTransform xslt = new XslCompiledTransform();
    should also work. I have never tried it, though.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now