2014-10-01 58 views
-1

我正在創建一個web應用程序,我需要點擊一個按鈕來瀏覽計算機上的文件夾,並在指定名稱的選定文件夾中創建新文件。我怎樣才能使用C#和ASP.NET?如何創建在asp.net中創建新文件的瀏覽按鈕?

+0

你嘗試過這麼遠嗎?試着回到這裏,回答具體的問題。 「爲我寫代碼」不是一個可以接受的問題。 – Stonz2 2014-10-01 12:55:22

回答

0

this link這裏有一個使用PDF文件的例子。代碼片斷在那裏發現:

private void Page_Load(object sender, System.EventArgs e) 
    { 
      //Set the appropriate ContentType. 
     Response.ContentType = "Application/pdf"; 
      //Get the physical path to the file. 
     string FilePath = MapPath("acrobat.pdf"); 
      //Write the file directly to the HTTP content output stream. 
     Response.WriteFile(FilePath); 
      Response.End(); 
    } 

在使用上面的代碼示例(發現here):

private void DownloadFile(string fname, bool forceDownload) 
{ 
    string path = MapPath(fname); 
    string name = Path.GetFileName(path); 
    string ext = Path.GetExtension(path); 
    string type = ""; 
    // set known types based on file extension 
    if (ext != null) 
    { 
    switch(ext.ToLower()) 
    { 
    case ".htm": 
    case ".html": 
     type = "text/HTML"; 
     break; 

    case ".txt": 
     type = "text/plain"; 
     break; 

    case ".doc": 
    case ".rtf": 
     type = "Application/msword"; 
     break; 
    } 
    } 
    if (forceDownload) 
    { 
    Response.AppendHeader("content-disposition", 
     "attachment; filename=" + name); 
    } 
    if (type != "") 
    Response.ContentType = type; 
    Response.WriteFile(path); 
    Response.End();  
} 
0

就其性質而言,ASP.NET最好有一個文件上傳控制。這在本地不受支持。你需要尋找一些東西來做到這一點:也許Silverlight會完成這項工作,或者尋找第三方組件,或者是一個JavaScript實用程序框架。我不確定什麼允許你創建一個開箱即用的文件。