0

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?

1 Answer 1

1

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);
10
  • When you say pathToXslt, you mean the full path to the xslt? like "mysharepointsite.com/sites/doclib/myxslt.xslt" ??
    – NICK
    Commented Oct 8, 2012 at 7:46
  • Also, file.OpenBinaryStream() is not working, OpenBinaryStream is throwing an error because It's not Available in Sandboxed Solutions.
    – NICK
    Commented Oct 8, 2012 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 Commented Oct 8, 2012 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
    Commented Oct 8, 2012 at 8:07
  • What I did is just, XMLTrnsfrm.Load("mysharepointsite.com/sites/MySite/doclib/myxslt.xslt");
    – NICK
    Commented Oct 8, 2012 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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