Problem with closing opened xl sheet or pdf doccument

Hi All,

I am generating a pdf doccument from an xls sheet on click of button in windows forms with following code and i am opening the created pdf doccumnet using System.Windows.Diagnostics.Process.Start("name") :

private void button8_Click(object sender, EventArgs e)

{

wb = new Workbook();

FileStream fstream = new FileStream("C:\\download.xls", FileMode.Open);

//Opening the Excel file through the file stream

wb.Open(fstream);

//Adding a new worksheet to the Workbook object

//Obtaining the reference of the newly added worksheet by passing its sheet index

Worksheet worksheet = wb.Worksheets[0];

worksheet.Name = "My Worksheet";

//Saving the Excel file

wb.Save("c:\\samplesearch.xml", FileFormatType.AsposePdf);

pdf2 = new Pdf();

pdf2.BindXML("c:\\samplesearch.xml", null);

pdf2.Save("c:\\samplesearchpdf.pdf");

fstream.Close();

//System.Diagnostics.Process.Start(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), string.Format("{0}.{1}","sample" ,"doc")));

proc = System.Diagnostics.Process.Start("C:\\samplesearchpdf.pdf");

}

Now if i close the form(application) i am getting an error that process is already in use.So,

i am closing the process in form close event and trying to delete the file from disk as follows:

private void Form1_FormClosed(object sender, FormClosedEventArgs e)

{

proc.WaitForExit(0);

//proc.Dispose();

proc.CloseMainWindow();

proc.Close();

//proc.Kill();

try

{

System.IO.File.Delete("C:\\samplesearchpdf.pdf");

}

catch (System.IO.IOException ex)

{

MessageBox.Show(ex.Message);

return;

}

}

This is always catching an exception that process is already in use and pdf doccument i s running.

Can you please help me in closing the opened doccument and then deleting it from the harddisk where i have stored it .There should not be any exceptions while closing the application.

Any help on this greatly appreciated.

Thanks in Advance

Bindu.

Hi Bindu,

I have tested your scenario, It looks the issue relates to Aspose.Pdf though I am not very sure. Could you post a query to Aspose.Pdf forum: http://www.aspose.com/community/forums/aspose.pdf-for-.net-java-and-reporting-services/20/showforum.aspx

And we will also check your case in more details on our end.

Thank you.

Ok thank you.

i posted in aspose.pdf forum but the same issue comes when we try to close .xls shhet also .Please let me know if you know something about it.As of now when it is not closed i am checking it and giving user a message to close and then waiting till it is closed then i deleted and it is working fine.Let me know if you know something other than this.

Thank You,

bindu.

Hi Bindu,

Thanks for further detials,

We will check it soon.

Thank you.

Hi bindu,

If you call System.Diagnostics.Process.Start,MS Excel will open the created file.The file is locked by MS Excel, it could not be writed by other process. So please close it in MS Excel, then run the programme again, or you will this error.