XML Output auf WEBDAV Verzeichnis

  • VB.NET

    XML Output auf WEBDAV Verzeichnis

    hallo alle zusammen,
    habe ein excel makro vorliegen,das mir ein vorliegende excel tabelle in eine xml datei exportiert und auf einem definierten share platziert (im Beispiel C:\lokal\) ... ich würd nun gerne die entstehende xml datei auf einem https webdav verzeichnis ablegen. pfad, user, pw sind bekannt ... wie kann ich dies am besten realisieren? bin scho leider seit langem raus aus der vb scene und würde mich über unterstützung freuen! vielen dank im voraus

    VB XML Makro

    VB.NET-Quellcode

    1. Option Explicit
    2. Sub XML_Export()
    3. Dim strSpaltenName
    4. strSpaltenName = ""
    5. Dim oSheet As Worksheet
    6. Set oSheet = Application.ActiveSheet
    7. ' Spaltenanzahl ermitteln
    8. Dim intCol
    9. intCol = 1
    10. Do Until Cells(1, intCol) = ""
    11. intCol = intCol + 1
    12. Loop
    13. intCol = intCol - 1
    14. 'MsgBox "Habe " & intCol & " Spalten gefunden...."
    15. ' Neue Datei schreiben, wenn Spaltenanzahl > 0
    16. If intCol > 0 Then
    17. Dim strFileName As String
    18. strFileName = "C:\Lokal\"
    19. strFileName = strFileName + oSheet.Name + "_" + CStr(Date)
    20. strFileName = strFileName + ".xml"
    21. ' Alte Datei löschen
    22. If Dir(strFileName) > "" Then Kill strFileName
    23. Open strFileName For Output As #1
    24. Dim intRow As Integer
    25. intRow = 2
    26. Dim x
    27. Print #1, "<?xml version=""1.0"" encoding=""iso-8859-1""?>"
    28. Print #1, MakeStartTag("Ergebnismenge")
    29. Do Until Cells(intRow, 1) = ""
    30. Print #1, vbTab & MakeStartTag(oSheet.Name)
    31. For x = 2 To intCol '2, weil Index in Spalte 1 ausgeblendet werden soll
    32. strSpaltenName = ReplaceSpecialChar(CStr(Cells(1, x).Value))
    33. Print #1, vbTab & vbTab & MakeStartTag(strSpaltenName) & FormatCell(Cells(intRow, x)) & MakeEndTag(strSpaltenName)
    34. Next
    35. intRow = intRow + 1
    36. Print #1, vbTab & MakeEndTag(oSheet.Name)
    37. Loop
    38. Print #1, MakeEndTag("Ergebnismenge")
    39. Close #1
    40. If intRow - 2 = 1 Then
    41. MsgBox "In die Datei '" & strFileName & "' wurde " & intRow - 2 & " Datensatz geschrieben!"
    42. Else
    43. MsgBox "In die Datei '" & strFileName & "' wurden " & intRow - 2 & " Datensätze geschrieben!"
    44. End If
    45. End If
    46. End Sub
    47. Function MakeStartTag(ByVal Text As String) As String
    48. MakeStartTag = "<" & Text & ">"
    49. End Function
    50. Function MakeEndTag(ByVal Text As String) As String
    51. MakeEndTag = "</" & Text & ">"
    52. End Function
    53. Function FormatCell(oCell As Range)
    54. If IsDate(oCell.Value) Then
    55. FormatCell = Format(oCell.Value, "yyyy-mm-dd\Thh:mm:ss")
    56. Exit Function
    57. End If
    58. 'If IsNumeric(oCell.Value) Then
    59. ' FormatCell = Replace(CStr(oCell.Value), ",", ".")
    60. ' Exit Function
    61. ' End If
    62. If InStr(1, oCell.Value, "&") Then
    63. FormatCell = Replace(CStr(oCell.Value), "&", "_x0026_")
    64. Exit Function
    65. End If
    66. FormatCell = oCell.Value
    67. End Function
    68. Function ReplaceSpecialChar(ByVal strText As String) As String
    69. If InStr(1, strText, " ") Then
    70. strText = Replace(strText, " ", "_x0020_")
    71. End If
    72. If InStr(1, strText, "&") Then
    73. strText = Replace(strText, "&", "_x0026_")
    74. End If
    75. ReplaceSpecialChar = strText
    76. End Function


    dies habe ich gefunden, wie binde ich es am besten ein (soll denn upload einer lokalen datei auf ein webdav verzeichnis realisieren):

    VB.NET-Quellcode

    1. Dim objRecord As New adodb.Record
    2. Dim objStream As New adodb.Stream
    3. sFilename = sFileToUpload
    4. objRecord.Open sFilename, "URL=" & sDAVFolder, adModeReadWrite, adCreateOverwrite, , sUserName, sPassword
    5. objStream.Open objRecord, adModeReadWrite, adOpenStreamFromRecord
    6. objStream.Type = adTypeBinary
    7. objStream.LoadFromFile sFileToUpload
    8. objStream.Flush