Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner


Importa in XML i dati di un file con i campi separati da tab


<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script language="vbscript" runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  fromTabbedToXML(vbTab, Server.MapPath("magazzino.tab"))
End Sub

Sub fromTabbedToXML(ByVal strDelimiter As String, ByVal strFilePath As String)
  Try
    Dim oDS As New DataSet()
    Dim strFields As String
    Dim oTable As New DataTable()
    Dim oRows As DataRow
    Dim intCounter As Int32 = 0
    oDS.DataSetName = "magazzino"
    oDS.Namespace = "magazzino"
    oDS.Tables.Add("articolo")
    Dim oSR As New StreamReader(strFilePath)
    oSR.BaseStream.Seek(0, SeekOrigin.Begin)
    For Each strFields In oSR.ReadLine().Split(strDelimiter)
      oDS.Tables(0).Columns.Add(strFields)
    Next
    oTable = oDS.Tables(0)
    While (oSR.Peek() > -1)
      oRows = oTable.NewRow()
      For Each strFields In oSR.ReadLine().Split(strDelimiter)
        oRows(intCounter) = strFields
        intCounter = intCounter + 1
      Next
      intCounter = 0
      oTable.Rows.Add(oRows)
    End While
    oDS.WriteXml(Server.MapPath("magazzino.xml"))
    Label1.Text = "Fatto"
  Catch ex As Exception
    Label1.Text = "Errore: <br>" & ex.Message
  End Try
End Sub
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>



Scarica il Codice...


Stampa la pagina


 








Inizio pagina

risorse per webmaster