|
Member 10666698 wrote: Do I have to access the file via browser and save locally or is there a quicker method? It has to be downloaded to a local path, and accessed from there.
Member 10666698 wrote: And if so, what would I have to do to dave the file to the local directory? Add a method to download it, and call it. There's an example here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy
thanks for the reponse, I thought as much. I used the code from your example
Many thanks
|
|
|
|
|
I'm listing the directories using FTPWebRequest and updating the data into a sql table. My code is:
If Con.State = ConnectionState.Closed Then Con.Open()
ObjEventlog.WriteEventLog("TimerListing_Task()", "Connection Is Open Now")
Dim Rs As SqlDataReader = com.ExecuteReader(CommandBehavior.CloseConnection)
While Rs.Read
ListBox1.Items.Add("Listing DeviceID-->" & Rs(0).ToString & " Start...")
ObjEventlog.WriteEventLog("TimerListing_Task()", "Table temp_Listing_result Is Refresh Now For Device ID---> " & Rs(0).ToString)
Dim arr() As String
Dim request As FtpWebRequest = WebRequest.Create("ftp://" & Rs(1) & ":" & Rs(2) & "/" & Rs(3))
request.Credentials = New NetworkCredential(Rs(4).ToString, Rs(5).ToString)
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
Dim response As FtpWebResponse = request.GetResponse()
Dim responseStream As Stream = response.GetResponseStream()
Dim reader As StreamReader = New StreamReader(responseStream)
ObjEventlog.WriteEventLog("TimerListing_Task()", "WebRequest is Created with ----> " & "ftp://" & Rs(1) & ":" & Rs(2) & "/" & Rs(3))
Dim loadData As String = ""
Dim lineNumber As Integer = 0
While loadData IsNot Nothing
loadData = reader.ReadLine()
arr = Split(loadData, vbNewLine)
For i = 0 To UBound(arr)
If Len(arr(i)) > 0 Then
Dim ss As String = arr(i)
ObjEventlog.WriteEventLog("TimerListing_Task()", "WebRequest Listing Result---> " & ss)
Dim isFolder As String = ss.Substring(0, 4)
If isFolder <> "drwx" Then
ss = Trim(ss.Substring(28))
ObjEventlog.WriteEventLog("TimerListing_Task()", "WebRequest Listing Result After Split---> " & ss)
Dim s() As String = vb.Split(ss, " ")
Dim modifyDate As String = s(1).ToString & " " & s(2).ToString & " " & s(3).ToString
Dim Clip() As String = vb.Split(s(4).ToString, ".")
If Clip.Length = 2 Then
ExecuteQuerys("insert into temp_Listing_result (deviceID, ClipName, ClipSize, ModifyDate, Extn) values(" & Rs(0) & ",'" & Clip(0).ToString & "','" & s(0).ToString & "','" & modifyDate & "','" & Clip(1).ToString & "')")
SqlQry = "update temp_Listing_result_process deviceID=" & Rs(0) & ", ClipName='" & Clip(0).ToString & "', ClipSize='" & s(0).ToString & "', ModifyDate='" & modifyDate & "', Extn='" & Clip(1).ToString & "' where deviceID=" & Rs(0) & ""
ExecuteQuerys(SqlQry)
Else
ExecuteQuerys("insert into temp_Listing_result (deviceID, ClipName, ClipSize, ModifyDate, Extn) values(" & Rs(0) & ",'" & Clip(0).ToString & "','" & s(0).ToString & "','" & modifyDate & "','')")
SqlQry = "update temp_Listing_result_process deviceID=" & Rs(0) & ", ClipName='" & Clip(0).ToString & "', ClipSize='" & s(0).ToString & "', ModifyDate='" & modifyDate & "' where deviceID=" & Rs(0) & ""
ExecuteQuerys(SqlQry)
End If
ListBox1.Items.Add(arr(i))
Else
ObjEventlog.WriteEventLog("TimerListing_Task()", "Folder Found ,Listing Not Done For Folder")
End If
End If
Quote: Here I've done Listing and throwing the data in the table temp_Listing_result.
If I'm inserting data only in single table then It's working fine but I want to update another temp_Listing_result_process table with previous table.
I'm getting wrong data: The data is only of one device and table is consisting only one directory data repetitively.
I'm having 4 directories, But when I listing it's listing only one device and inserting the same data again and again.
Please share your experiences.
Thanks!
|
|
|
|
|
Hello everyone
I would like to convert an XML file to Excel (xls, xlsx) using the stylesheet referenced (XSL). This is done easily opening the XML file in Excel and confirming the XSL reference. I need this to be executed from a VBScript however:
1. Open XML in Excel with style applies
2. Save to a central directory as workbook (e.g. xls)
I have only a basic understanding of VBScript. Any help is greatly appreciated
p.s. VBA apparently know a method called workbook.openXML with XSL as a parameter. I assume there is no equivalency in VBScript?
|
|
|
|
|
If you know how to do it manually in Excel, use the developer functions to record a macro - this will show the code needed to do it programatically
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Hello Chris
thanks for the quick reply. Here is what I have following your suggestion:
Sub Macro1()
ChDir "D:\some directory..."
Workbooks.OpenXML Filename:= _
"D:\some directory/somefile.xml", _
Stylesheets:=Array(1)
End Sub
This works fine in VBA (i.e. running the macro from Excel). Unfortunately, I have to execute the code from within a VBScript and the language does not seem to acknowledge the Workbooks.OpenXML reference. Any ideas?
|
|
|
|
|
You will nead to create an Excel application - Look here for some examples[^]
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Okay, slowly getting there. This is what I have:
Dim xlApp, xlWkb, SourceFolder,TargetFolder,file
Set xlApp = CreateObject("excel.application")
Set fs = CreateObject("Scripting.FileSystemObject")
Const xlNormal=1
filestr="D:\some directory\some file.xml"
TargetFolder="D:\some directory\xls"
xlApp.Visible = False
Set xlApp = CreateObject("Excel.Application")
Set xlWkb = xlApp.Workbooks.OpenXML(filestr, Array(1), 2)
BaseName= fs.getbasename(filestr)
FullTargetPath=TargetFolder & "\" & BaseName & ".xls"
xlWkb.SaveAs FullTargetPath, xlNormal
xlWkb.close
Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
End Sub
This will open the XML fiel, apply the style sheet and save it as a workbook. However, the code is interrupted by the opo-up window in Ezxcel prompting the user to apply the XSL fiel or not. The code continues only after clicking 'OK'. The code needs to run uninterrupted. Parameter 3 of OpenXML should be the load method: 2 = xlXmlLoadImportToList. Not sure I am using the correct parameter?
|
|
|
|
|
Okay, this seems like a confirmed bug:
http://support.microsoft.com/kb/307230/en-US
The solution is to convert to HTML first, then to xls. The workaround code in VBA:
Sub Macro3()
Dim oXML As Object, oXSL As Object
Set oXML = CreateObject("MSXML.DOMDocument")
Set oXSL = CreateObject("MSXML.DOMDocument")
oXML.Load "c:\customers.xml"
oXSL.Load "c:\customers.xsl"
Dim sHTML As String
sHTML = oXML.transformNode(oXSL)
Open "c:\customers.htm" For Output As #1
Print #1, sHTML
Close #1
Dim oApp As Excel.Application
Set oApp = CreateObject("excel.application")
oApp.Visible = True
oApp.Workbooks.Open "c:\customers.htm"
End Sub
This fails when trying to save the HTML file, presumably because the file cannot be referenced that way in VBScript:
Open "c:\customers.htm" For Output As #1
What do I need to change to save this as HTML?
p.s. I realise this forum is VB but I could not find a disgnated VBScript section
|
|
|
|
|
It fails because you shouldn't write in the root. The PC will explode if you do that.
Member 10666698 wrote: p.s. I realise this forum is VB but I could not find a disgnated VBScript section No surprise there, VBA has been abandoned with VB6.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
While that is good to know I still have no idea how to do this in VBScript. Assume I know nothing about VBScript
|
|
|
|
|
|
Second sentence in that link: Despite Microsoft's best efforts to kill VBA off
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how to read any specific text from Web Browser tool and put it into TextBox control.
it would be better it you tell me how can i read text line by line from Web Browser tool and put it into TextBox control.
thanks,
Virendra
|
|
|
|
|
Virendra Singh Bhanu wrote: it would be better It would be better if you posted in the ASP.NET forum[^].
|
|
|
|
|
but i don't know ASP.Net
is it not possible in vb.net?
|
|
|
|
|
You have not explained in any detail what you mean by "read line by line from Web Browser tool". However, I would suggest using the WebBrowser Class[^], which allows you to interact with any internet site.
|
|
|
|
|
Did you mean from the WebBrowser control? Or from any browser-application that the user has opened?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Let's say that I have an object called Employee with the properties Name and Department.
Next I have a List(Of Employee) with say 5 employees in it. Each of these 5 employees are member of one of 10 possible different departments. Perhaps they are each member of a different department, perhaps they are all members of the same department, etc. This is an unknown.
How can I get the distinct departments from my list ?
There is List.Distinct, but it seems I can only get distinct entire objects (employees) through that.
Any help much appreciated.
Best regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Probably by creating another List (or other collection class) which only contains departments. Go through all your employee records adding the department to the second list.
|
|
|
|
|
|
Johan Hakkesteegt wrote: Each of these 5 employees are member of one of 10 possible different departments. Perhaps they are each member of a different department, perhaps
they are all members of the same department, etc. This is an unknown. One employee in one department, not one employee in multiple departments. Check.
Imports System.Collections.Generic
Module Module1
Class Employee
Public Property Name As String
Public Property Department As String
End Class
Sub Main()
Dim zeList As New List(Of Employee)
zeList.Add(New Employee() With {.Name = "John", .Department = "IT"})
zeList.Add(New Employee() With {.Name = "Jane", .Department = "IT"})
zeList.Add(New Employee() With {.Name = "Pete", .Department = "Management"})
Dim departments As IEnumerable(Of String) = zeList.Select(Function(e) e.Department).Distinct()
For Each department As String In departments
Console.WriteLine(department)
Next
Console.ReadLine()
End Sub
End Module
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Last night I woke up and figured Richard's answer myself, but this is the "one-liner" that I was after.
Thanks Eddy !
My advice is free, and you may get what you paid for.
|
|
|
|
|
Eddy Vluggen wrote: zeList.Select(Function(e) e.Department).Distinct()
I looked and looked and wondered where the Function(e) comes from and what is it doing x=>
So I have not looked at VB since before linq was invented.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How do I keep a class object "alive" in a Windows Service?
I have a simple class object (clsWatcher) that monitors a folder using an instantiation of the FileSystemWatcher class. It works great. When a change is made to the folder being "watched" it triggers a log entry.
When I use the clsWatcher as a form-level object in a standard Windows Forms EXE, it works perfectly as long as the windows form is open. When the form closes, it dies and no watching is done. Perfect.
When I transfer this class to a SYSTRAY application, it continues to work correctly. As long as the SYSTRAY application is not exited, the clsWatcher works properly. When I exit the SYSTRAY application, it dies and no watching is done. Perfect.
When I transfer this class to a Windows Service, it does not work as desired. The service starts, the clsWatcher instantiates, and then the service "finalizes" and the clsWatcher dies even though the service is still "started" and no errors were logged (I have an Application Log feature to send messages that can be observed during start up and errors.)
How do I keep the service/application "running" in order to keep the instantiated clsWatcher object alive?
|
|
|
|