Bind folder structure to a Treeview

Hi

Please transilate the following code for me to C#:This function collects and displays the files in a specified folder as hypelinks on a webpage. I would like to attach this to a TreeView control on an aspx webpage.Thanks in advance.I would also like to have the file list as hyperlinks ,so that the files opens when clicked on.

Function ShowOfferFileList(folderspec)
dim FileExtension
dim FilePath
Dim fso, f, f1, fc, strList
dim i
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
FilePath = cstr(f1.name)
FileExtension = GetExtension(FilePath)
'FileExtension = mid(FilePath, len(FilePath) - 3, 3)
'FileExtension = mid(FilePath, 1, 3)
if UCase(FileExtension) = "HTML" or UCase(FileExtension) = "MPP" or UCase(FileExtension) = "PDF" or UCase(FileExtension) = "MHT" or UCase(FileExtension) = "MHTML" then
i = i + 1
FilePath = TheOfferDataPath & "\" & FilePath
strList = strList & "<A href=" & FilePath & ">"
strList = strList & "<" & i & "> " & f1.name & "</A>" ' is a " & UCase(FileExtension)
strList = strList & "<BR>"
end if
Next
'ShowFileList = strList
TheOffer = strList
End Function




Answer this question

Bind folder structure to a Treeview

  • DoonNicolas&amp;#33;

    Wendy Biyela wrote:
    Please transilate the following code for me to C#


    Hi Wendy, these forums are not meant to only post code that needs to be translated. It is about people who encouter a problem when trying to write an application. Just translation from one language to another is not a real problem. Dive into it and do it yourself.

  • Frances83

    Editting doesn't seem to work

    Hint: take a look at the System.IO namespace, and especially the DirectoryInfo and FileInfo classes. DirectoryInfo contains methods like GetFiles()...



  • Mirricle

    Thanks for your participation on the MSDN Forum, but we are not here to translate full pieces of code but we are here to find solutions.

    Here is a thread with the same question: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=565485&SiteID=1&mode=1


  • lord_8

    Rick van den Bosch wrote:
    Hey Sibusiso,

    maybe I interpreted the code wrong, but this seems to be oldscool VB and not VB.Net. The link you provided is for converting VB.Net code to C#.

    Wendy, did you get any further

    True, it is old school so there is no way to convert it to C# unless translated.



  • Shadowsoul

    Wendy Biyela wrote:

    Hi

    Please transilate the following code for me to C#:This function collects and displays the files in a specified folder as hypelinks on a webpage. I would like to attach this to a TreeView control on an aspx webpage.Thanks in advance.I would also like to have the file list as hyperlinks ,so that the files opens when clicked on.

    Function ShowOfferFileList(folderspec)
    dim FileExtension
    dim FilePath
    Dim fso, f, f1, fc, strList
    dim i
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(folderspec)
    Set fc = f.Files
    For Each f1 in fc
    FilePath = cstr(f1.name)
    FileExtension = GetExtension(FilePath)
    'FileExtension = mid(FilePath, len(FilePath) - 3, 3)
    'FileExtension = mid(FilePath, 1, 3)
    if UCase(FileExtension) = "HTML" or UCase(FileExtension) = "MPP" or UCase(FileExtension) = "PDF" or UCase(FileExtension) = "MHT" or UCase(FileExtension) = "MHTML" then
    i = i + 1
    FilePath = TheOfferDataPath & "\" & FilePath
    strList = strList & "<A href=" & FilePath & ">"
    strList = strList & "<" & i & "> " & f1.name & "</A>" ' is a " & UCase(FileExtension)
    strList = strList & "<BR>"
    end if
    Next
    'ShowFileList = strList
    TheOffer = strList
    End Function

    Hi

    Convert your code in this link http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

    Hope this helps



  • kuvve

    Hey Sibusiso,

    maybe I interpreted the code wrong, but this seems to be oldscool VB and not VB.Net. The link you provided is for converting VB.Net code to C#.

    Wendy, did you get any further

  • Bind folder structure to a Treeview