Thursday, 30 March 2017

Writing Directories into File & Reading from File C#




sample.aspx
=====================================================

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>


<%

Context.Response.ContentType = "text/plain";

    DirectoryInfo[] cDirs = new DirectoryInfo(@"D:\").GetDirectories();

    StreamWriter sw = new StreamWriter("D:/CDriveDirs.txt", true);
 
        foreach (DirectoryInfo dir in cDirs)
        {
            sw.WriteLine(dir.Name);
            sw.WriteLine("\n");
            Response.Write(dir.Name);
            Response.Write("\n");
       
       }

        sw.Flush();
        sw.Close();
%>
=====================================================

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>


<%

Context.Response.ContentType = "text/plain";

    DirectoryInfo[] cDirs = new DirectoryInfo(@"D:\").GetDirectories();

   
       StreamReader sr = new StreamReader("D:/CDriveDirs.txt");
 
           String line;
               
           while((line=sr.ReadLine())!=null)
           {
         
               Response.Write(line+"\n");
         
           }  
 
        sr.Close();
%>

=====================================================

No comments:

Post a Comment