Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting vbscript.asp to c#.net(4.0)

Status
Not open for further replies.

bind

IS-IT--Management
Dec 13, 2004
25
Hello,

Would anyone be willing to assist me in converting the following web form into c#.net(4.0)?

I've been working on this for a while now, just can't seem to get it working properly.

Thanks a lot all.

<% sub ListFolderContents(path)

dim fs, folder, file, item, url

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

'Display the target folder and info.

Response.Write("<li><b>" & folder.Name & "</b> - ")
if folder.SubFolders.Count > 0 then
Response.Write("<b>" & folder.SubFolders.Count & "</b> show directories - ")
end if
Response.Write("(" & Round(folder.Size / 1024) & " KB total.)" _
& vbCrLf)

Response.Write("<ul>" & vbCrLf)

'Display a list of sub folders.

for each item in folder.SubFolders
ListFolderContents(item.Path)
next

'Display a list of files.

for each item in folder.Files
if(item.Name <> LCase("index.asp")) then
url = MapURL(item.path)
Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> - " _
& item.Size & " bytes, " _
& "last modified on " & item.DateLastModified & "." _
& "</li>" & vbCrLf)
end if
next

Response.Write("</ul>" & vbCrLf)

Response.Write("</li>" & vbCrLf)

end sub

function MapURL(path)

dim rootPath, url

'Convert a physical file path to a URL for hypertext links.

rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")

end function %>
 
what do you have so far? the biggest changes will be the separation of the template (html) and the logic (code behind).
next is replacing calls like CreateObject() with the appropiate .net managed object. In this case
Code:
var directory = new System.IO.DirectoryInfo(name of directory)
//use directory to navigate subdirectories and files.
I would also recommend mapping the data from Directory/FileInfo to simple POCOs (plain old compiled objects) and passing the POCO(s) to the view to render the html.
Code:
class ViewOfDirectory
{
   public string Name {get; set;}
   public ViewOfDirectory[] SubDirectories {get; set;}
   public string[] FileNames {get; set;}
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Jason Meckley,

Perfect, that's exactly what I needed to get a start on this.

Thank you sir, much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top