ASP.NET FTP

Kodla Büyü

merkur

Aktif Üye
Mesajlar
158
merhaba arkadaşlar
aspnet te ftp deki bi klasörün içindeki dosyaları nasıl gösterebilirim acaba? yardımcı olursanız sevinirim.
 
public List<string> getFileList(string folder)
{
this.folder += folder;
List<string> files = new List<string>();
try
{
Application.DoEvents();

//Create FTP request

FtpWebRequest request = FtpWebRequest.Create(new Uri(FtpServer+folder)) as FtpWebRequest;

request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(UserName, Password);
request.UsePassive = this.UsePassive;
request.UseBinary = true;
request.KeepAlive = false;

//Read the server's response
//this.Text = "Retrieving List...";
Application.DoEvents();

FtpWebResponse response = request.GetResponse() as FtpWebResponse;
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

while (!reader.EndOfStream)
{
Application.DoEvents();
files.Add(reader.ReadLine());
}

//Clean-up
reader.Close();
responseStream.Close(); //redundant
response.Close();
return files;
}
catch
{
files.Add("Bağlantı Kurulamadı...");
return files;
}


}
 
Private Function OutputDirectory(directory As System.IO.DirectoryInfo, parentNode As TreeNode) As TreeNode
' validate param
If directory Is Nothing Then
Return Nothing
End If

' create a node for this directory

Dim DirNode As New TreeNode(directory.Name)

' get subdirectories of the current directory

Dim SubDirectories As System.IO.DirectoryInfo() = directory.GetDirectories()

' OutputDirectory(SubDirectories[0], "Directories");

' output each subdirectory

For DirectoryCount As Integer = 0 To SubDirectories.Length - 1



OutputDirectory(SubDirectories(DirectoryCount), DirNode)
Next

' output the current directories file

Dim Files As System.IO.FileInfo() = directory.GetFiles()

For FileCount As Integer = 0 To Files.Length - 1



DirNode.ChildNodes.Add(New TreeNode(Files(FileCount).Name))
Next
' if the parent node is null, return this node
' otherwise add this node to the parent and return the parent

If parentNode Is Nothing Then



Return DirNode
Else



parentNode.ChildNodes.Add(DirNode)

Return parentNode
End If
End Function

yaptım hocam bu kodla treeview de listelettim çok sağolasın
 
Geri
Üst