大大好 我有兩個ImageButton1,ImageButton2,一個creatPDF的Function
想問有辦法做到
點ImageButton1呼叫creatPDF Function時不跳"另存新檔"的訊息(mark掉的地方)
點ImageButton2呼叫creatPDF Function時跳出"另存新檔"的訊息(mark掉的地方)
請問有辦法做到嗎??
public void creatPDF()
{
.
.
.
/* Response.Clear();
Response.ContentType = "application/pdf";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.Cache.SetCacheability(HttpCacheability.NoCache);*/
.
.
.
/*Response.WriteFile(filePath);
Response.Write(doc1);
Response.End();
Response.Close();*/
PdfWriter.Close();
}
creatPDF()這個函數加入一個變數來控制就行
然後在裡面判斷變數要做那些事情
public void creatPDF(bool msg)
{
if(msg)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.Cache.SetCacheability(HttpCacheability.NoCache);*/
}
else
{
Response.WriteFile(filePath);
Response.Write(doc1);
Response.End();
Response.Close();
}
PdfWriter.Close();
}
按鈕地方這樣寫
protected void ImageButton1_Click(object sender, EventArgs e)
{
creatPDF(true);
}
protected void ImageButton2_Click(object sender, EventArgs e)
{
creatPDF(false);
}
我之前有做個類似的功能
button.Click += HandleClick;
private void HandleClick(object sender, EventArgs e)
{
//執行功能時,將button.Text帶進去Function
CopyToFile(btn.Text);
}
private void CopyToFile(string btnName)
{
//Do something...
if (btnName=="funtion1")
{
}
if (btnName=="funtion2")
{
}
}
感謝homura的說明,補充如下:
switch (btnName)
{
case "品管":
foldername = DateTime.Now.ToString("yyyyMMdd");
targetDirectory = @"w:\◎品管課\";
break;
case "業務":
foldername = DateTime.Now.ToString("yyyyMMdd");
targetDirectory = @"w:\◎業務部\";
break;
case "研發":
foldername = DateTime.Now.ToString("yyyyMMdd");
targetDirectory = @"w:\◎研發部\";
break;
case "個人":
foldername = DateTime.Now.ToString("yyyyMMdd");
targetDirectory = textBox1.Text.ToString() + @"\";
break;
default:
targetDirectory = textBox1.Text.ToString() + @"\";
break;
}
受益良多 感謝大大們