Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to fetch data from the list (which I am getting in XML) and then I need to apply the XML data to my XSLT so that it can produce HTML output.

I tried using SPUtility.GetGenericSetupPath to get the XSLT which resides in 14 hive but SPUtility.GetGenericSetupPath doesn't supported in Sandbox web parts.

I got that I will be uploading my XSLT somewhere into SharePoint Library, but the real question is How will I consume it?

SPUtility.GetGenericSetupPath to get the XSLT isn't working in Sandbox.

How will I get the path of XSLT?

This is what I have done with Farm Web Part, now I'm converting it into Sandbox Web Part.

            //Transform XML To HTML using ContactList.XSLT
            XslCompiledTransform XMLTrnsfrm = new XslCompiledTransform();
            XMLTrnsfrm.Load(SPUtility.GetGenericSetupPath("TEMPLATE\\LAYOUTS\\ContactsXSLT.xslt"));

Any other solution in mind guys?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

In a sandboxed solution you'll not be able to read from the file system so you need to put the XSLT file into a SharePoint document library then read it like this:

var file = web.GetFile(pathToXslt);
var bytes = file.OpenBinary();
var stream = new MemoryStream(bytes);
var reader = new XmlTextReader(stream);
var XMLTransfrm = new XslCompiledTransform();
XMLTransfrm.Load(reader);
share|improve this answer
    
When you say pathToXslt, you mean the full path to the xslt? like "mysharepointsite.com/sites/doclib/myxslt.xslt"; ?? –  NICK Oct 8 '12 at 7:46
    
Also, file.OpenBinaryStream() is not working, OpenBinaryStream is throwing an error because It's not Available in Sandboxed Solutions. –  NICK Oct 8 '12 at 7:59
    
It can be either the full path http://mysharepointsite.com/sites/MySite/doclib/myxslt.xslt, server relative /sites/MySite/doclib/myxslt.xslt or site relative doclib/myxslt.xslt –  Per Jakobsen Oct 8 '12 at 8:02
    
It's throwing Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. –  NICK Oct 8 '12 at 8:07
    
What I did is just, XMLTrnsfrm.Load("mysharepointsite.com/sites/MySite/doclib/myxslt.xslt"); –  NICK Oct 8 '12 at 8:07
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.