2016-10-24 5 views
0

私はフォルダ(ファイル)を作成します。ボタン(btnGenerate_Click)をクリックすると、pdfファイルを作成してフォルダに保存する必要があります。しかし、 "C:\ User \ VS \ Intra \ Intra.Admin \ File \"のパスの一部を見つけることができませんでしたが、パスの場所は正しいです... 。エラーメッセージの表示:「パスの一部を見つけることができませんでした」

protected void btnGenerate_Click(object sender, EventArgs e) 
 
     { 
 
      string FilePath = MapPath("~/File/"); //here! 
 
       
 

 
      iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 20f, 20f, 20f, 20f); 
 
      PdfWriter.GetInstance(pdfDoc, new FileStream(FilePath, FileMode.Create)); 
 
      StringWriter sw = new StringWriter(); 
 
      HtmlTextWriter hw = new HtmlTextWriter(sw); 
 

 
      GridView1.AllowPaging = false; 
 
      GridView1.HeaderRow.Cells[1].Text = "Message"; 
 
      GridView1.HeaderRow.Font.Bold = true; 
 
      GridView1.RenderControl(hw); 
 

 
      StringReader sr = new StringReader(sw.ToString()); 
 
      HTMLWorker htmlparser = new HTMLWorker(pdfDoc); 
 
      PdfWriter.GetInstance(pdfDoc, Response.OutputStream); 
 
      pdfDoc.Open(); 
 
      htmlparser.Parse(sr); 
 
      pdfDoc.Close(); 
 

 
      Response.Write(pdfDoc); 
 

 
      Response.ContentType = "Application/pdf"; 
 
      Response.WriteFile(FilePath); 
 
      Response.End(); 
 

 
     }

+0

ファイルの名前はどこですか?これはファイル名のように使用しようとしているフォルダ名です。 – Steve

答えて

0

ファイルパスはディレクトリです。ファイル名を追加する必要があります。

string FilePath = MapPath("~/File/" + fileName); 
+0

私はこの状況でfileName .....の文字列を作成する方法ではありません。FilePath = MapPath( "〜/ File/doc.pdf"); –

+0

*この状況でFileNameを作成する方法はわかりませんが、あなたのアドバイスに従って、それをstringに変更しました。FilePath = MapPath( "〜File/doc.pdf); –

関連する問題