to save xml file in Vb.net

Public Function UploadCourseXML(ByVal fileStream As String, companyID As Integer, ByVal tokenID As String) As String Implements ICorePointService.UploadCourseXML

        If (Not IsCustomerAuthentication(companyID, tokenID)) Then
            Throw New Exception("Authentication failed. Please provider Company ID and Token ID")
        End If

        Dim doc As XDocument = XDocument.Parse(fileStream)

        doc.Save("Update_XML")' error occures here... Access to the path c:\...etc.  is denied
                                             ..  i want to save this in solution explorer

        Return "result"
    End Function

Answers


Refer this link :

http://support.microsoft.com/kb/301233

This for windows & web also

Imports System.IO Imports System.Net Imports System.Xml

Public Class Form1

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'To just download xml text
    'Download text and save
    Dim wc As New WebClient
    Dim xmlText As String = wc.DownloadString("http://www.localcallingguide.com/xmllocalexch.php?exch=015800")
    File.WriteAllText("new file path.xml", xmlText)


    'Or

    'To load stream directly into XML Document :

    'Get data in stream
    Dim webRequest As WebRequest = webRequest.Create("http://www.localcallingguide.com/xmllocalexch.php?exch=015800")
    Dim webResponse As WebResponse = webRequest.GetResponse
    Dim webStream As Stream = webResponse.GetResponseStream

    'Optionally
    'If you want you can read text from stream
    'Dim reader As New StreamReader(webStream)
    'reader.ReadToEnd 'will give same output as wc.downloadString()


    'Load stream
    Dim xmlDoc As New XmlDocument
    xmlDoc.Load(webStream)

    'select any level nodes using xpath
    Dim Nodes As XmlNodeList = xmlDoc.SelectNodes("//lca-data/prefix/exch")

    'iterate in selected nodes
    For Each node As XmlNode In Nodes
      RichTextBox1.AppendText(node.InnerText & vbCrLf)
    Next


  End Sub

End Class

You'll get a Access to the path '...' is denied error if the folder is flagged ReadOnly. You need to remove this flag prior to saving the file.

Dim info As DirectoryInfo = New DirectoryInfo("C:\folder1\folder2\folder3")

If (info.Exists AndAlso ((info.Attributes And FileAttributes.[ReadOnly]) = FileAttributes.[ReadOnly])) Then
    info.Attributes = (info.Attributes Xor FileAttributes.[ReadOnly])
End If

If you're writing to an existing file, also make sure the file is not flagged ReadOnly. Just change DirectoryInfo to FileInfo.

Dim info As FileInfo = New FileInfo("C:\folder1\folder2\folder3\file.ext")

You may refer to the below given link to find out your problem,

http://support.microsoft.com/kb/2623670#method4


Need Your Help

Unable to iterate over list

java

I'm appending to a list then throwing that list into a function below:

comboBox width depending on longest item

c# combobox

i've got a ComboBox that i generate dynamically and fill with some items. i would like to set this control's width to the width of the longest item. how do i count the display width of some text?