The following code save pdf to local app folder; how do I save to a network folder?
I have tried different way by providing network path but it always adds network path string to local drive path like:
C:\WebApplication\WebApplication\FileServer\FileFoldertemp\employee.pdf
protected void Save(object sender, EventArgs e)
{
string sDate = txtDate.Value;
string name = txtHeadName.Value;
Document document = new Document(PageSize.LETTER, 100f, 100f, 10f, 10f);
iTextSharp.text.Font NormalFont = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
BaseColor color = null;
document.Open();
//Header Table
table = new PdfPTable(2);
table.TotalWidth = 550f;
table.LockedWidth = true;
table.SetWidths(new float[] { .3f, 2.3f });
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
table.AddCell(cell);
//Separater Line
color = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#A9A9A9"));
document.Add(table);
table = new PdfPTable(2);
table.HorizontalAlignment = Element.ALIGN_LEFT;
table.SetWidths(new float[] { 0.3f, 1f });
table.SpacingBefore = 10f;
cell = PhraseCell(new Phrase("Client Record", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.UNDERLINE, BaseColor.BLACK)), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
table.AddCell(cell);
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.PaddingBottom = 30f;
table.AddCell(cell);
table = new PdfPTable(4);
table.TotalWidth = 800f;
table.SetWidths(new float[] { 4.5f, 4.5f, 2.35f, 1.75f });
table.TotalWidth = 440f;
table.LockedWidth = true;
table.SpacingBefore = 20f;
table.HorizontalAlignment = Element.ALIGN_RIGHT;
table.AddCell(PhraseCell(new Phrase("DATE:", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
table.AddCell(PhraseCell(new Phrase(sDate, FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 4;
cell.PaddingBottom = 10f;
table.AddCell(cell);
string strUploadDestination = ConfigurationManager.AppSettings["UploadDestination"].ToString();
string sUser = "Temp";
string dmzPath = @strUploadDestination + "\\" + sUser + "\\";
string sFile = "MyFile";
document.Add(table);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
string strSessVar = dmzPath + "StayInPlace _" + sID + ".pdf";
var uncPath = @"\\FileServer\FileFolder$\temp\employee_" + sFile + "_" + ID + ".pdf";
//Response.AddHeader("Content-Disposition", "attachment; filename=" + sFile + ";");
//Response.ContentType = "application/pdf";
//Response.Buffer = true;
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
//Response.BinaryWrite(bytes);
Response.WriteFile(Server.MapPath(uncPath));
Response.WriteFile(Server.MapPath(uncPath));
Response.End();
Response.Close();
}
}