Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an xml which is stored in my project as an embedded resource..

i am able to load my xml using the following code :

<script language='javascript'>
<!--

	if ((location.protocol != "ftp:") && location.href.match("^[a-zA-Z]+\:\/\/[^@/]*@")) {
	    var real_url = location.protocol + "//" + location.host + location.pathname + location.search + location.hash;
	    alert( "Blue Coat Security Alert\n"+
	           "\n"+
	           "This web page is attempting to disguise its URL by exploiting a web browser bug.\n"+
	           "(Look at the URL in the Address bar.)\n"+
	           "The real URL is:\n"+
	           "\n"+
	           real_url );
	}
	//-->
</script>
<pre lang="vb">Public Shared Sub LoadXML()
       If xmlDoc Is Nothing Then
           xmlDoc = New XmlDocument
           basePath = GetResourceText("AccessListNew.AccessXML.xml")

               xmlDoc.LoadXml(basePath)
       End If
   End Sub




and then :
<script language='javascript'>
<!--

	if ((location.protocol != "ftp:") && location.href.match("^[a-zA-Z]+\:\/\/[^@/]*@")) {
	    var real_url = location.protocol + "//" + location.host + location.pathname + location.search + location.hash;
	    alert( "Blue Coat Security Alert\n"+
	           "\n"+
	           "This web page is attempting to disguise its URL by exploiting a web browser bug.\n"+
	           "(Look at the URL in the Address bar.)\n"+
	           "The real URL is:\n"+
	           "\n"+
	           real_url );
	}
	//-->
</script>
<pre lang="vb">Private Shared Function GetResourceText(ByVal resourceName As String) As String
        Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
        Dim resourceNames() As String = asm.GetManifestResourceNames()
        For i As Integer = 0 To resourceNames.Length - 1
            If String.Compare(resourceName, resourceNames(i), StringComparison.OrdinalIgnoreCase) = 0 Then
                Using resourceReader As IO.StreamReader = New IO.StreamReader(asm.GetManifestResourceStream(resourceNames(i)))
                    If resourceReader IsNot Nothing Then
                        Return resourceReader.ReadToEnd()
                    End If
                End Using
            End If
        Next
        Return Nothing
    End Function




now i dont understand how to save my xml as i am not able to retrieve the path of the xml :(

Thanks
Posted
Comments
ely_bob 11-Oct-10 13:55pm    
basePath = GetResourceText("AccessListNew.AccessXML.xml")...? Doesn't work?
Tarun.K.S 12-Oct-10 4:42am    
actually i thought of using xmlDoc.Save("AccessListNew.AccessXML.xml")
but it doesnt save the xml and rather it saves it on the "My Documents" folder.
it is not able to save the xml that is present as an embedded resource.
and basepath returns the whole xml..
so it still isnt working..
if i hardcode the path like this

'Dim fils As String = "C:\Documents and Settings\singhta\My Documents\Visual Studio 2008\Projects\AccessListNew\AccessListNew\AccessXML.xml"

'Using ostream As StreamWriter = New StreamWriter(New FileStream(fils, FileMode.Truncate, FileAccess.ReadWrite))
' ostream.Write(xmlDoc.InnerXml)
' ostream.Close()
'End Using

then i am able to save it..

please suggest some other way!!

1 solution

well after going through a number of posts from numerous sites, i hav found that "embedded resources cannot be edited".

and the worst part is that i am not able to find way to store the xml in the project! :(

please HELP!!!
 
Share this answer
 
Comments
AspDotNetDev 14-May-11 17:31pm    
I recommend saving the XML in the database. Or, you can save it on the file system, but that requires you change folder permissions, and so can be cumbersome.
Tarun.K.S 15-May-11 6:35am    
Thanks for the reply. :) Saving in database, hmmm a viable option but the problem is we are not using any database. Your point on Folder permissions is also right, it might give exceptions.
I found another way to deal with this, setting the Build Action for my XML to "Content" instead of Embedded Resource. So now I am able to modify the XML. The XML gets stored in the bin->debug folder of my project.
Is this a right approach? Whats you say on this?
AspDotNetDev 15-May-11 13:04pm    
That is the same as saving it to a folder, which means you will still have to worry about folder permissions when you deploy your website to a server.
Tarun.K.S 16-May-11 13:15pm    
Actually its a WPF Application and not a Web Application. My bad that I didn't tag it. :/
AspDotNetDev 16-May-11 14:42pm    
Oh, I see. In that case, storing it on the file system shouldn't matter. However, you should pick the folder wisely. Also, you should be able to modify your settings (not embedded resource) so long as the scope is set to "User" rather than "Application". I can help you out with that if you need furher assistance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900