Avatar of hqdev
Flag for Canada asked on

Using project xml file as string

Hi experts,

In my application I have to use XML for some Sharepoint ribbon definition.
This is all working fine but the XML is in Strings.
I found it difficult to maintain and read XML in strings, I would like to use xml files and convert those file to string at runtime.
How can I use xml files in the project to be used as string??
Also I don't want those file to be deployed, I just need to use those files within the project.
I've tried to put those files in a resource file and use something like that:
Dim a As String = My.Resources.Resource.mainTab (mainTab is an XML file in resources.resx)
But this implied a deployment to sharepoint resources and anyway it doesn't work.

Any help appreciated.

Visual Basic.NETEditors IDEs

Avatar of undefined
Last Comment

8/22/2022 - Mon
Shahan Ayyub


Could you please check this one:

        Dim xmldoc As New XmlDocument
        Dim XmlContents As String = My.Resources.mainTAB   ' Read File as string
        xmldoc.LoadXml(XmlContents)                                       ' Load it in XML

        ' Here is your processing for XML
        ' You can use XmlNodeList as well.

        Dim TagBasedString As String = xmldoc.InnerXml          ' Here values along with tag comes.    
        Dim ValuesBasedString As String = xmldoc.InnerText    ' Here only values of tag comes

Open in new window


In SharePoint my.resources doesn't work.
I need a way to read the entire xml file and convert it to string.
Even if I have to deploy the file to SharePoint.
I've tried xmldoc.load("http://myserver/MyFiles/mainTab.xml) but I get an access error.
It's probably because it's the ASP.NET account that tries to read the file instead of the actual logged user.
Shahan Ayyub

use LoadXML:


instead of:

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

LoadXML takes a string, that's what I'm using now, I want to load the XML from a file.
Shahan Ayyub


When you write:

'My.Resources.Resource.mainTab'  it returns a string containing all the TAGs of the XML file....Agree ??

>>>>I want to load the XML from a file.
This 'My.Resources.Resource.mainTab' is the xml file added in resource of project. So get the TAG(s) as string and use LoadXML method to load it and treat as a XML file now. so you may continue processing...

That's what I've tried, but as I said, "My.resource" doesn't work in SharePoint, so I can't use it, I have to find another way.
I've succeeded by using file.open, but it works only on the server, client can't access local files with file.open since it's the ASP.NET account that tries to open the file.
I've tried impersonat current user before file.open but it doesn't work either.
If I could make My.resource work in SharePoint, that would solve my problem.
I've got that message when using my.resource:
"Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "My.Resources.Resource.resources" was correctly embedded or linked into assembly "TelList" at compile time, or that all the satellite assemblies required are loadable and fully signed."
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question