Hack Forums
[.NET] URI Format not supported - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] URI Format not supported (/showthread.php?tid=5744323)

Pages: Pages 1 2


URI Format not supported - aGFjaw-- - Oct 28, 2017

I need some help edit a simple tool, that read a xml file from local pc.
I need to make it able to read xml from web instead of local pc, until I get error.
Can anyone give me an hint if I send project?


RE: URI Format not supported - Barret - Oct 28, 2017

(Oct 28, 2017 11:37 AM)aGFjaw-- Wrote:  I need some help edit a simple tool, that read a xml file from local pc.
I need to make it able to read xml from web instead of local pc, until I get error.
Can anyone give me an hint if I send project?

uri class in .net works only if http://, https:// or file:// is used on the beginning of an address.


RE: URI Format not supported - aGFjaw-- - Oct 28, 2017

Sure, but there should be an error somewhere.

Little screenshoot under spoiler.

Spoiler (Click to View)


RE: URI Format not supported - v.e.n.o.m - Oct 28, 2017

(Oct 28, 2017 11:37 AM)aGFjaw-- Wrote:  I need some help edit a simple tool, that read a xml file from local pc.
I need to make it able to read xml from web instead of local pc, until I get error.
Can anyone give me an hint if I send project?

Can you share that link of that xml web or any code ?? 😅 😅 😅


RE: URI Format not supported - CoderEX - Oct 28, 2017

If I an not mistaken, you will need to create a stream that fetches the XML file from a specific URL.

Example Code:
Code
Dim URLString As [String] = " http://localhost/books.xml"
Dim reader As New XmlTextReader(URLString)



RE: URI Format not supported - Rhez - Oct 28, 2017

(Oct 28, 2017 01:37 PM)aGFjaw-- Wrote:  Sure, but there should be an error somewhere.

Little screenshoot under spoiler.

Spoiler (Click to View)

Maybe because you have an empty variable?
On your button mnuOpen, you need to browse first for nothing before the variable "Filename" get the data.


RE: URI Format not supported - aGFjaw-- - Oct 29, 2017

Here is full code.

Code
Imports System.Xml
Imports System.Text
Imports System.IO

Public Class MainForm
  Dim mFileName As String = String.Empty
  Dim mDocument As XmlDocument = Nothing

Private Sub mnuOpen_Click(sender As System.Object, e As System.EventArgs) Handles mnuOpen.Click
  If OpenDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            'FileName = OpenDialog.FileName
            FileName = "http://vb.net-informations.com/xml/img/product.xml"
            LoadFile()
  End If
End Sub

Private Sub LoadFile()
  If mDocument Is Nothing Then
    mDocument = New XmlDocument
  End If

  Dim Content As String = File.ReadAllText(FileName, Encoding.Default)
  mDocument.LoadXml(Content)
  rtbXmlSource.Text = Content
  trvNodes.Nodes.Clear()
  FillTreeView(trvNodes.Nodes, mDocument.DocumentElement)
End Sub

Private Sub FillTreeView(TreeNodes As TreeNodeCollection, Xml_Node As XmlNode)
  Dim NewNode = TreeNodes.Add(Xml_Node.Name)
  NewNode.Tag = Xml_Node

  For Each Node As XmlNode In Xml_Node.ChildNodes
    FillTreeView(NewNode.Nodes, Node)
  Next
  trvNodes.ExpandAll()
End Sub

Private Property FileName As String
  Get
    Return mFileName
  End Get
  Set(value As String)
    lblFileName.Text = value
    mFileName = value
  End Set
End Property

Private Sub trvNodes_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles trvNodes.AfterSelect
  If trvNodes.SelectedNode IsNot Nothing Then
    PropertyGrid1.SelectedObject = trvNodes.SelectedNode.Tag
  End If
End Sub
End Class



RE: URI Format not supported - v.e.n.o.m - Oct 29, 2017

Its a good idea to download that file in Temp folder and then read it from XmlReader and on

OnFormClosingEvent delete that xml file from Temp directory.


RE: URI Format not supported - aGFjaw-- - Oct 29, 2017

Yes, I thought to do so, but I would like to read it directly from the web.


RE: URI Format not supported - v.e.n.o.m - Oct 29, 2017

if you can share that link then i will create and upload the project.


RE: URI Format not supported - aGFjaw-- - Oct 29, 2017

Sure :

Download

Scan


RE: URI Format not supported - The White House - Oct 29, 2017

Thanks for releasing it to us


RE: URI Format not supported - CoderEX - Oct 29, 2017

You would replace the OpenFileDialog code with the code I provided up top. You need to create a stream that requests/reads the file from a specific URL.


RE: URI Format not supported - aGFjaw-- - Oct 29, 2017

Already tried but it does not work.
I also tried with WebClient.
There should be more stuffs to edit, something I don't understand.


RE: URI Format not supported - CoderEX - Oct 29, 2017

(Oct 29, 2017 11:34 AM)aGFjaw-- Wrote:  Already tried but it does not work.
I also tried with WebClient.
There should be more stuffs to edit, something I don't understand.

What does your current code look like? I looked at the last code you posted, and it seems like you are still using OpenFileDialog.