Click here to Skip to main content
16,004,529 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
i try to create date wise folder and save report in same folder, folder created, but file not save in that folder,

please help me

What I have tried:

C#
private void jayShahDailyReportsToolStripMenuItem_Click(object sender, EventArgs e)
{
    var folderPath = (@"d:/");
    var foldername = DateTime.Now.ToString("yyyy-MM-dd");
    if (!Directory.Exists(folderPath + foldername))
    Directory.CreateDirectory(folderPath + foldername);
    var savepath = System.IO.Path.Combine(folderPath, foldername);
    // Weaving Sales Pending Contract

    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(Application.StartupPath + @"\Reports\Jay Shah\Weaving Sales Pending Contract Register.RPT");
    crvContractRegister.ReportSource = cryRpt;
    crvContractRegister.Refresh();
    cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "Weaving Sales Pending Contract Register.pdf");
    MessageBox.Show("Exported Successful");
}
Posted
Updated 12-Sep-17 21:54pm
v3

1 solution

This is problematic:
C#
var folderPath = (@"d:/");

Should be:
C#
var folderPath = (@"d:\");

Also, this:
C#
cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "Weaving Sales Pending Contract Register.pdf");

should be:
C#
cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Application.StartupPath + @"\Weaving Sales Pending Contract Register.pdf");

but will override the original.

Also, when joining paths and filenames, you should do the following:
C#
var filename = "Weaving Sales Pending Contract Register.pdf";
var fullFilePathAndName = System.IO.Path.Combine(Application.StartupPath, filename);
cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fullFilePathAndName);

This will ensure that the path is correctly created.
 
Share this answer
 
v2
Comments
Deep Bagadiya 14-Sep-17 3:49am    
i try to save export file in new created folder, not in startuppath,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900