Hi I can search all the images with .jpg extension and pass it to the fancybox gallery , The issue is i just want the images of particular productid
for instance if a product has 5 images , and they are saved as (productid_imagenumber.jpg) , therefore a product with productid 99 will be saved as 99_1.jpg , 99_2.jpg similarly 99_5.jpg,
I can pass the productID but i cant find a away just to get the images of that productID , instead of getting all the images which is done by the function below:
Dim directory As DirectoryInfo = New System.IO.DirectoryInfo("C:Images\")
Dim allImages() = directory.GetFiles("*.jpg", SearchOption.AllDirectories)
Dim strContent As String = ""
For Each image As FileInfo In allImages
Dim strTemp As String = (String.Format("<img src=""{0}"" />", image.Name))
strContent = "<a class=""fancybox-thumb"" rel=""fancybox-thumb1"" href=""" & image.Name + image.Extension & """ title="""">" & _
"<img src=""" & image.Name + image.Extension & """ alt="" /></a>"
Next
If Not String.IsNullOrEmpty(strContent) Then
Return String.Format("<div id=""product-lightbox""><p>{0}</p></div>", strContent)
Else
Return String.Empty
End If
End Function
Can any one give any suggestion or assistance on how to do this.
Try this:
Dim images = (From img In directory.GetFiles("*.jpg", IO.SearchOption.AllDirectories)
Where img.Name.Contains("_") _
AndAlso img.Name.Split("_"c)(0) = productID).ToList
Ok, you are using .NET 2.0:
Dim allProductIDImages As New List(Of IO.FileInfo)
For Each img As IO.FileInfo In directory.GetFiles("*.jpg", IO.SearchOption.AllDirectories)
If img.Name.Contains("_") Then
Dim ID As String = img.Name.Split("_"c)(0)
If ID.Equals(productID) Then
allProductIDImages.Add(img)
End If
End If
Next
Another - possibly faster - approach is to let GetFiles pre-search:
Dim pattern As String = String.Format("*{0}_*.jpg", productID)
Dim allProductIDImages() As IO.FileInfo = _
directory.GetFiles(pattern, IO.SearchOption.AllDirectories)
Related
I have a file folder that contains pdf files. The sql database is not directly related to the files. For example, I have "Invoice_co_355_24636.pdf" and "Invoice_co_355_25127.pdf" in the Invoices folder. I query the database and find that Invoice "24636" is not paid and "25127" is marked paid in full, so I would like to delete "Invoice_co_355_25127.pdf" at that point since it is paid.
So what I'm doing is getting all the file names from the folder, parsing each file to get just the last numbers, (which correlate to the database). If the database shows that one or more of the Invoices has been paid, I would like to delete the file.
I have successfully, (below), been able to parse the server file names as
"InvNo" as the parsed file name, (which corelates to the database), and
"InvNoFull", which is the full database file name that needs to be deleted if it is marked as paid in the database.
But after getting the file names and the parsed file names, I do not know how to actually compare it to the database and then delete. Any help is appreciated.
Dim files() As String = Directory.GetFiles(Server.MapPath("/Contents/Invoices/" + Variable.ToString() + "/Co/" + ddlCo.SelectedValue.ToString() + "/"))
For Each file As String In files
Dim InvNo As String = Path.GetFileNameWithoutExtension(file)
Dim InvNoFull As String = Path.GetFileName(file)
InvNo = InvNo.Substring(InvNo.LastIndexOf("_") + 1, InvNo.Length - InvNo.LastIndexOf("_") - 1)
Dim CnStr As String = (ConfigurationManager.ConnectionStrings("ClientConnectionString").ConnectionString)
Dim adp As SqlDataAdapter = New SqlDataAdapter("select OrderBilling.OrderId from orderBilling Left Outer Join Orders on OrderBilling.OrderId = Orders.OrderId Where Orders.CompanyId = " & ddlCo.SelectedValue.ToString() & " And Orders.OwnerId = " & Variable.ToString() & " And OrderBilling.PaidInFull = 'False'", CnStr)
Dim ds As DataSet = New DataSet()
adp.Fill(ds, "outBill")
For Each Row As DataRow In ds.Tables(0).Rows
For Each Coll As DataColumn In ds.Tables(0).Columns
Dim s As String = Row(Coll.ColumnName).ToString()
If s <> InvNo Then
Dim FileToDelete() As String
FileToDelete = Directory.GetFiles(Server.MapPath("/Contents/Invoices/" + Variable.ToString() + "/Co/" + ddlCo.SelectedValue.ToString() + "/" + InvNoFull))
If System.IO.File.Exists(FileToDelete.ToString()) = True Then
System.IO.File.Delete(FileToDelete.ToString())
'MsgBox("File Deleted")
End If
End If
Next
Next
Next
With help from Mary but this deletes all the files in the folder, but I want it to delete only the files not returned in the database query:
Private Sub DeletePaidInvoices(OwnerID2 As String, CompanyID As String)
Dim InvoicePath = "/Contents/Invoices/" & OwnerID2 & "/Co/" & CompanyID & "/"
Dim files() As String = Directory.GetFiles(Server.MapPath(InvoicePath))
Dim lst = GetInvoiceInfo(CInt(CompanyID), CInt(OwnerID2))
For Each file As String In files
Dim InvNo As String = Path.GetFileNameWithoutExtension(file)
Dim InvNoFull As String = Path.GetFileName(file)
InvNo = InvNo.Substring(InvNo.LastIndexOf("_") + 1, InvNo.Length - InvNo.LastIndexOf("_") - 1)
'Debug.Print(InvNo) 'To check your substring, will not be in release version
For Each i As Integer In lst
Dim s As String = i.ToString()
If s <> InvNo Then
Dim FileToDelete As String
FileToDelete = "Invoice_co_" & CompanyID & "_" & InvNo & ".pdf"
If System.IO.File.Exists(Server.MapPath(InvoicePath & FileToDelete.ToString())) = True Then
System.IO.File.Delete(Server.MapPath(InvoicePath & FileToDelete.ToString()))
End If
End If
Next
Next
End Sub
Call your delete method from, say, a button passing the variable from the user interface.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim CompID = ddlCo.SelectedValue.ToString()
Dim OwnerID = "comes from somewhere"
DeletePaidInvoices(OwnerID, CompID)
End Sub
The delete method gets the file list. I have no idea about Server.MapPath but I assume you do. Next we get a List(Of Integer) representing the results of you database query (the OrderID's). Next we enter the For loop. I added a Debug line to see what is being returned by SubString code. As you can see it is simpler code to loop through a list.
Private Sub DeletePaidInvoices(OwnerID As String, CompanyID As String)
Dim InvoicePath = $"/Contents/Invoices/{OwnerID}/Co/{CompanyID}/"
Dim files() As String = Directory.GetFiles(Server.MapPath(InvoicePath))
Dim lst = GetInvoiceInfo(CInt(CompanyID), CInt(OwnerID))
For Each file As String In files
Dim InvNo As String = Path.GetFileNameWithoutExtension(file)
Dim InvNoFull As String = Path.GetFileName(file)
InvNo = InvNo.Substring(InvNo.LastIndexOf("_") + 1, InvNo.Length - InvNo.LastIndexOf("_") - 1)
Debug.Print(InvNo) 'To check your substring, will not be in release version
For Each i As Integer In lst
Dim s As String = i.ToString()
If s <> InvNo Then
Dim FileToDelete() As String
FileToDelete = Directory.GetFiles(Server.MapPath(InvoicePath & InvNoFull))
If System.IO.File.Exists(FileToDelete.ToString()) = True Then
System.IO.File.Delete(FileToDelete.ToString())
'MsgBox("File Deleted")
End If
End If
Next
Next
End Sub
The data retrieval is in a separate function. Use Using blocks to make sure your connections and commands are closed and disposed. Always use parameters with Sql Server. There is a bit of Linq magic at the end to create the list from the DataTable.
Private Function GetInvoiceInfo(CompanyID As Integer, OwnerID As Integer) As List(Of Integer)
Dim dt As New DataTable
Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("ClientConnectionString").ConnectionString),
cmd As New SqlCommand("select OrderBilling.OrderId
from orderBilling
Left Outer Join Orders on OrderBilling.OrderId = Orders.OrderId
Where Orders.CompanyId = #CompanyID
And Orders.OwnerId = #OwnerID
And OrderBilling.PaidInFull = #Paid;", cn)
cmd.Parameters.Add("#CompanyID", SqlDbType.Int).Value = CompanyID
cmd.Parameters.Add("#OwnerID", SqlDbType.Int).Value = OwnerID
cmd.Parameters.Add("#Paid", SqlDbType.Bit).Value = False
cn.Open()
dt.Load(cmd.ExecuteReader)
End Using
Dim lstOrderID As List(Of Integer) = (From dRow In dt.AsEnumerable() Select dRow.Field(Of Integer)(0)).ToList
Return lstOrderID
End Function
The actual deleting of the files (or moving to a Paid folder) is up to you.
Am trying to create am xml document using string builder as follows. string builder having the exact value as expected. but it does not write to the xml file. following is the code
mssql = "select ID, ParentID, OrderID, Title, Start, End, PercentComplete, Expanded, Summary From Project"
Dim buildXML As New StringBuilder
buildXML.Append("<?xml version=""1.0"" encoding=""utf-8""?><Project> <Tasks>")
Dim mycommand As OdbcCommand
mycommand = New OdbcCommand(mssql, dbcon)
dbcon.Open()
Dim reader As OdbcDataReader
reader = mycommand.ExecuteReader
While reader.Read
buildXML.Append("<Task>" & _
"<ID>1</ID>" & _
"<ParentID />" & _
"<Start>" & reader.Item("Start") & "</Start>" & _
"<End>" & reader.Item("End") & "</End>" & _
"<Title>" & reader.Item("Title") & "</Title>" & _
"<PercentComplete>" & reader.Item("PercentComplete") & "</PercentComplete>" & _
"<Summary>" & reader.Item("Summary") & "</Summary>" & _
"<Expanded>" & reader.Item("Expanded") & "</Expanded>" & _
"<OrderID>" & reader.Item("OrderID") & "</OrderID>" & _
"</Task>")
End While
buildXML.Append("</Tasks> <Dependencies /></Project>")
reader.Close()
dbcon.Close()
'everything work fine up to this
Dim XMLDocument As System.Xml.XmlDocument = New System.Xml.XmlDocument()
XMLDocument.LoadXml(buildXML.ToString())
Dim Output As New XmlTextWriter(Server.MapPath("~/App_Data/gantt.xml"), System.Text.Encoding.UTF8)
XMLDocument.WriteTo(Output)
saving the document will result in empty document, does anyone know the reason?
Please modify your code as follows:
1) Remove Xml declaration (xml version and encoding) from buildXML. Only you node info should be there.
2) Modify your commented code as shown below (Use Save instead of WriteTo)
Dim XMLDocument As System.Xml.XmlDocument = New System.Xml.XmlDocument()
XMLDocument.LoadXml(buildXML.ToString())
Dim Output As New XmlTextWriter(Server.MapPath("~/App_Data/gantt.xml"), System.Text.Encoding.UTF8)
XMLDocument.Save(Output)
I am trying to create a code that will convert multiple selected files to one pdf file . Currently the code exports the selected files in to a zip file. But I want to open all the selected files in one single pdf file .
For your assistance I am providing the code that exports all files into one zip file.
In the code below there are two table mentioned. one is document and another is vacancyapplication. In the document table all the files are stored guid is the unique id in the document table.
Imports System
Imports System.Web
Imports System.IO
Imports System.Collections.Generic
Imports Ionic.Zip
Imports System.Linq
Imports NLog
Public Class download_bulk_cv : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim _logger As Logger = LogManager.GetCurrentClassLogger()
Dim vacancy = New Vacancy(context.Request("v"))
context.Response.Clear()
context.Response.ContentType ="application/zip"
context.Response.AddHeader("content-disposition", "attachment; filename=" & vacancy.Title.Replace(" ", "_") & "_" & Now.ToString("yyyy-MMM-dd-HHmmss") & ".zip")
Dim files = New List(Of String)()
For Each docPath As String In From row As DataRow In DB.GetData("select guid, originalfilename from document where id in (select candidatecvid from vacancyapplication where id in (" & context.Request("a").ToString() & "))").Rows Let guid = row.Item("guid").ToString() Select HttpContext.Current.Server.MapPath("~/documents") & "\" & Left(guid, 1) & "\" & Right(guid, 1) & "\" & guid & "." & System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)
If File.Exists(docPath) Then
files.Add(docPath)
'_logger.Info(docPath)
End If
Next
Using zip As New ZipFile()
zip.AddFiles(files.ToArray(), "CVs") '.AddFile(docPath, "CVs")
zip.AddEntry("info.txt", files.Count.ToString.ToString() & "CVs archived", Encoding.Default)
zip.Save(context.Response.OutputStream)
End Using
context.Response.End()
End Sub
End Class
i have written the following code to merge the pdf documents but its not working
Edited code
Public Class preview_bulk_cv : Implements IHttpHandler
''Implements IDisposable
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim _logger As Logger = LogManager.GetCurrentClassLogger()
Dim vacancy = New Vacancy(context.Request("v"))
Dim files = New List(Of String)()
Dim sourceFiles = New List(Of String)()
Dim directorypath As String = HttpContext.Current.Server.MapPath("~/documents") & "\download\" & Now.ToString("yyyy-MMM-dd") & "\" & vacancy.Title.Replace(" ", "_") & "\"
Dim pdf_document As iTextSharp.text.Document = Nothing
Dim pdf_copier As iTextSharp.text.pdf.PdfCopy = Nothing
context.Response.Clear()
context.Response.ContentType = "application/pdf"
context.Response.AddHeader("content-disposition", "attachment; filename=" & vacancy.Title.Replace(" ", "_") & "_" & Now.ToString("yyyy-MMM-dd-HHmmss") & ".pdf")
For Each docPath As String In From row As DataRow In DB.GetData("select guid, originalfilename from document where id in (select candidatecvid from vacancyapplication where id in (" & context.Request("a").ToString() & "))").Rows Let guid = row.Item("guid").ToString() Select HttpContext.Current.Server.MapPath("~/documents") & "\" & Left(guid, 1) & "\" & Right(guid, 1) & "\" & guid & "." & System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)
Dim epath As String = HttpContext.Current.Server.MapPath("~/documents") & "\download\" & Now.ToString("yyyy-MMM-dd") & "\" & vacancy.Title.Replace(" ", "_") & "\" & Now.ToString("yyyy-MMM-dd-HHmmss") & ".pdf"
Converter.ConvertDocument(docPath, epath)
If File.Exists(epath) Then
sourceFiles.Add(epath)
End If
If File.Exists(docPath) Then
files.Add(docPath)
'_logger.Info(docPath)
End If
Next
Dim all_source_files As String() = sourceFiles.ToArray()
Dim docs As PdfDocument() = New PdfDocument(all_source_files.Length - 1) {}
For i As Integer = 0 To all_source_files.Length - 1
Dim reader As New PdfReader(all_source_files(i))
' Using reader As New iTextSharp.text.pdf.PdfReader(all_source_files(i))
Dim finalpdf As String = HttpContext.Current.Server.MapPath("~/documents") & "\download\" & Now.ToString("yyyy-MMM-dd") & "\" & vacancy.Title.Replace(" ", "_") & "\finalcv.pdf"
If i = 0 Then
pdf_document = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
pdf_copier = New iTextSharp.text.pdf.PdfCopy(pdf_document, New IO.FileStream(finalpdf, IO.FileMode.Create))
pdf_document.Open()
End If
For page_num As Integer = 1 To reader.NumberOfPages
pdf_copier.AddPage(pdf_copier.GetImportedPage(reader, page_num))
Next
' End Using
Next
pdf_copier.Close()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
I am new with vb.net . I appreciate your kind assistance.
This is an example of code to combine an array of PDFs into 1 merged PDF, it requires a reference to the iTextSharp dll I mentioned in my comment. If you can save each file individually to a PDF now, you can use something like System.IO.Directory.GetFiles(your_directory) to get the array of file names and then combine them with something like the code here:
' This requires a reference to the iTextSharp library (http://sourceforge.net/projects/itextsharp/)
Dim pdfs() As String ' all of your PDF files you'd like to merge
Dim output_pdf As String ' the output file
Dim pdf_document As iTextSharp.text.Document = Nothing
Dim pdf_copier As iTextSharp.text.pdf.PdfCopy = Nothing
For i As Integer = 0 To pdfs.Length - 1
Using pdf_reader As New iTextSharp.text.pdf.PdfReader(pdfs(i))
If i = 0 Then
pdf_document = New iTextSharp.text.Document(pdf_reader.GetPageSizeWithRotation(1))
pdf_copier = New iTextSharp.text.pdf.PdfCopy(pdf_document, New IO.FileStream(output_pdf, IO.FileMode.Create))
pdf_document.Open()
End If
For page_num As Integer = 1 To pdf_reader.NumberOfPages
pdf_copier.AddPage(pdf_copier.GetImportedPage(pdf_reader, page_num))
Next
End Using
Next
pdf_copier.Close()
Here is the code for converting any documents to pdf files and merging them into one single pdf file
<%# WebHandler Language="VB" Class="PDFMerge" %>
Imports System
Imports System.Web
Imports System.IO
Imports System.Collections.Generic
Imports Ionic.Zip
Imports System.Linq
Imports NLog
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.Text.RegularExpressions
Public Class PDFMerge : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim _logger As Logger = LogManager.GetCurrentClassLogger()
Dim vacancy = New Vacancy(context.Request("v"))
Dim sourceFiles = New List(Of String)()
For Each docPath As String In From row As DataRow In DB.GetData("database query").Rows Select HttpContext.Current.Server.MapPath("~/Downloads") & "\" System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)
Dim epath As String = HttpContext.Current.Server.MapPath("~/Downloads") & "\" & Now.ToString("yyyy-MMM-dd") & "\" & vacancy.Title.Replace(" ", "_") & "\" & Now.ToString("yyyy-MMM-dd-HHmmss") & ".pdf"
Converter.ConvertDocument(docPath, epath)
If File.Exists(epath) Then
sourceFiles.Add(epath)
End If
Next
Dim OutputFileName As String = HttpContext.Current.Server.MapPath("~/Downloads") & "\" & Now.ToString("yyyy-MMM-dd") & "\" & vacancy.Title.Replace(" ", "_") & "\" & vacancy.Title.Replace(" ", "_") & ".pdf"
PDFMerge.MergeFiles(OutputFileName, sourceFiles.ToArray)
Dim mPDFFile As FileStream = File.OpenRead(OutputFileName)
Dim mPDFFileBuffer(mPDFFile.Length - 1) As Byte
mPDFFile.Read(mPDFFileBuffer, 0, mPDFFileBuffer.Length)
mPDFFile.Close()
System.Diagnostics.Process.Start(OutputFileName)
context.Response.Clear()
context.Response.ContentType = "application/pdf"
context.Response.AddHeader("Content-Disposition", "attachment;filename=" & OutputFileName)
context.Response.AddHeader("Content-Length", mPDFFileBuffer.Length)
context.Response.OutputStream.Write(mPDFFileBuffer, 0, mPDFFileBuffer.Length)
mPDFFileBuffer = Nothing
context.Response.Flush()
context.Response.End()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Shared Sub MergeFiles(destinationFile As String, sourceFiles As String())
Try
Dim f As Integer = 0
Dim reader As New PdfReader(sourceFiles(f)) ' we create a reader for a certain document
Dim n As Integer = reader.NumberOfPages ' we retrieve the total number of pages
'Console.WriteLine("There are " + n + " pages in the original file.");
Dim document As New Document(reader.GetPageSizeWithRotation(1)) ' step 1: creation of a document-object
Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream(destinationFile, FileMode.Create)) ' step 2: we create a writer that listens to the document
document.Open() ' step 3: we open the document
Dim cb As PdfContentByte = writer.DirectContent
Dim page As PdfImportedPage
Dim rotation As Integer
' step 4: we add content
While f < sourceFiles.Length
Dim i As Integer = 0
While i < n
i += 1
document.SetPageSize(reader.GetPageSizeWithRotation(i))
document.NewPage()
page = writer.GetImportedPage(reader, i)
rotation = reader.GetPageRotation(i)
If rotation = 90 OrElse rotation = 270 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, _
reader.GetPageSizeWithRotation(i).Height)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, _
0)
'Console.WriteLine("Processed page " + i);
End If
End While
f += 1
If f < sourceFiles.Length Then
reader = New PdfReader(sourceFiles(f))
' we retrieve the total number of pages
'Console.WriteLine("There are " + n + " pages in the original file.");
n = reader.NumberOfPages
End If
End While
' step 5: we close the document
document.Close()
Catch e As Exception
Dim strOb As String = e.Message
End Try
End Sub
Public Function CountPageNo(strFileName As String) As Integer
' we create a reader for a certain document
Dim reader As New PdfReader(strFileName)
' we retrieve the total number of pages
Return reader.NumberOfPages
End Function
End Class
To convert the documents use a third party library like Apose Words for .net. Create a separate class as converter and a function ConvertDocument(ByRef docPath As String, ByRef expPath As String) . If you already have all the files in pdf you dont need to convert them...
you only need to merge them
I hope this codes will help many people
I am trying to process this json document using JSON.NET.
With the VB.NET code:
Dim o As JObject = JObject.Parse(json)
Dim results As List(Of JToken) = o.Children().ToList
Dim count As Integer = 0
For Each item As JProperty In results
Dim snippet As String = String.Empty
Dim URL As String = String.Empty
Dim source As String = String.Empty
item.CreateReader()
Select Case item.Name
Case "response"
snippet = item.Last.SelectToken("docs").First.Item("snippet").ToString
URL = item.Last.SelectToken("docs").First.Item("web_url").ToString
source = ControlChars.NewLine & "<font size='2'>" & item.First.SelectToken("docs").First.Item("source").ToString & "</font>" & ControlChars.NewLine
tbNews.Text &= "<a href=" & URL & " target='new'>" & snippet & "</a> - " & source
End Select
Next
I am only receiving the first document as a result. Can someone advise as to how I can get the 1st - Nth documents as a complete list?
The docs are 2 levels deep, you're only looping in the top level. Try this...
Dim parsedObject = JObject.Parse(json)
Dim docs = parsedObject("response")("docs")
For Each doc In docs
Dim snippet As String = doc("snippet")
Dim URL As String = doc("web_url")
Dim source As String = doc("source")
'....
Next
Using ASP/VB, I'm trying to get rid of some duplication in a list box that is coming from an XML document.
Sorry if this is a daft question, I'm new to this.
I've tried various things, but nothing has worked. Here is the code - thanks for any help / assistance!
Function getAssets(ByVal siteid As String) As String
Dim oAssets As New Xteam.XteamWebService
Dim strAssets As String = ""
Dim oDoc As New XmlDocument
'Dim oNode As XmlNode
strAssets = oAssets.ReadHAssetCodes(siteid)
oDoc.LoadXml(strAssets)
For Each Node As XmlNode In oDoc.SelectSingleNode("XteamAssets")
lstHAssets.Items.Add(New ListItem(Node("hassetdescription").InnerText, Node("hassetcode").InnerText))
Next
lstHAssets.Items.Insert(0, "--Please Select--")
Return "ToSender"
End Function
There's probably a more efficient way but this will work.
Function getAssets(ByVal siteid As String) As String
Dim oAssets As New Xteam.XteamWebService
Dim strAssets As String = ""
Dim oDoc As New XmlDocument '
Dim oNode As XmlNode
strAssets = oAssets.ReadHAssetCodes(siteid)
oDoc.LoadXml(strAssets)
Dim strAryUniqueValues as string()
Dim strUniqueValues as string = ""
Dim i as int = 0
Dim strSearchPair as string
For Each Node As XmlNode In oDoc.SelectSingleNode("XteamAssets")
strSearchPair = "~" & Node("hassetdescription").InnerText & "/" & Node("hassetcode").InnerText & "~"
' see if these values have been included already, if not then add them
if instr(strUniqueValues,strSearchPair) = -1 then
strAryUniqueValues(i) = strSearchPair
strUniqueValues = strUniqueValues & strAryUniqueValues(i)
i = i + 1
end if
Next
'now loop back through and build your listbox
Dim strAryPair as string()
For each strPair in strAryUniqueValues
strAryPair = split(strPair,"/")
lstHAssets.Items.Add(New ListItem(Replace(strAryPair(0),"~",""),Replace(strAryPair(1),"~",""))
Next
lstHAssets.Items.Insert(0, "--Please Select--")
Return "ToSender"
End Function