Click here to Skip to main content
15,880,427 members
Home / Discussions / C#
   

C#

 
GeneralRe: string is not recognized Pin
PIEBALDconsult23-Sep-09 17:55
mvePIEBALDconsult23-Sep-09 17:55 
GeneralRe: string is not recognized Pin
Luc Pattyn24-Sep-09 0:27
sitebuilderLuc Pattyn24-Sep-09 0:27 
GeneralRe: string is not recognized Pin
Ashfield23-Sep-09 21:04
Ashfield23-Sep-09 21:04 
GeneralRe: string is not recognized Pin
DaveyM6924-Sep-09 0:00
professionalDaveyM6924-Sep-09 0:00 
GeneralRe: string is not recognized Pin
Luc Pattyn24-Sep-09 0:29
sitebuilderLuc Pattyn24-Sep-09 0:29 
GeneralRe: string is not recognized Pin
Ashfield24-Sep-09 1:23
Ashfield24-Sep-09 1:23 
GeneralRe: string is not recognized Pin
Rabia_Arif24-Sep-09 5:19
Rabia_Arif24-Sep-09 5:19 
QuestionFileSystemWatcher and Window Service. Pin
Escocia23-Sep-09 6:43
Escocia23-Sep-09 6:43 
First, sorry my poor English.

goal: Modify and print an excel file that is being stored in a directory that is being observed.

Trouble: File Sharing.

Explain:

I have created a Windows service.This service contain a FileSystemWatcher Object who has got an "Created" delegate.

Code Constructor Service
Fsw = new FileSystemWatcher();
          
            Fsw.Path = "c:\\DirListen";
            Fsw.Filter = "*.xls";
            Fsw.Created +=new FileSystemEventHandler(Fsw_Changed);


When the user save an excel file in "c:\\DirListen" the delegate is raised up and then I must modify the excel file and then print. The problem is that this file is being used by the SSOO (i Think) and I can't use it. I always get errors due to that delegate is raised up before the file has finished to save. I do not want to use timer objects, but with this problem... Please, any suggestion or solution?

Code Delegate

void  Fsw_Changed(object sender, FileSystemEventArgs e)
{
    try
    {
        Excel.Application oXL;
        Excel._Workbook oWB;
        Excel._Worksheet oSheet;
        oXL = new Excel.Application();
        oWB = oXL.Workbooks.Open(e.FullPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
        object opc = Type.Missing;
        oSheet = (Excel._Worksheet)oWB.Sheets.get_Item(2);
        oSheet.Activate();
        oSheet.Cells[1, 1] = "change";
        oSheet.Cells[2, 4] = "another change";
        oXL.Visible = true;
      	oSheet.PrintOut(1, 2, 1, false, "printer", true, false, Type.Missing);
        FileStream fs2 = null;
        StreamWriter sw2 = null;
       oWB.Close(false, e.FullPath, Type.Missing);
       
        oXL.Quit();
        foreach (Process p in Process.GetProcessesByName("EXCEL"))
        {
            p.Kill();
        }
    }
    catch (Exception ex)
    {
        FileStream fs = null;
        StreamWriter sw = null;
            fs = new FileStream("c:\\error.log", FileMode.CreateNew, FileAccess.Write);
            sw = new StreamWriter(fs);
            sw.WriteLine(ex.ToString());
    }
}



Many Many Thanks. Smile | :)

regards
AnswerRe: FileSystemWatcher and Window Service. Pin
0x3c023-Sep-09 6:55
0x3c023-Sep-09 6:55 
AnswerRe: FileSystemWatcher and Window Service. Pin
Luc Pattyn23-Sep-09 8:25
sitebuilderLuc Pattyn23-Sep-09 8:25 
GeneralRe: FileSystemWatcher and Window Service. Pin
Escocia24-Sep-09 0:59
Escocia24-Sep-09 0:59 
GeneralRe: FileSystemWatcher and Window Service. Pin
Luc Pattyn24-Sep-09 1:11
sitebuilderLuc Pattyn24-Sep-09 1:11 
QuestionData from Scanner to Database Pin
Dambod23-Sep-09 6:40
Dambod23-Sep-09 6:40 
AnswerRe: Data from Scanner to Database Pin
Manas Bhardwaj23-Sep-09 6:51
professionalManas Bhardwaj23-Sep-09 6:51 
GeneralRe: Data from Scanner to Database Pin
Dambod23-Sep-09 6:57
Dambod23-Sep-09 6:57 
GeneralRe: Data from Scanner to Database Pin
Dave Kreskowiak23-Sep-09 9:31
mveDave Kreskowiak23-Sep-09 9:31 
AnswerRe: Data from Scanner to Database Pin
Henry Minute23-Sep-09 6:58
Henry Minute23-Sep-09 6:58 
GeneralRe: Data from Scanner to Database Pin
Dambod23-Sep-09 7:17
Dambod23-Sep-09 7:17 
GeneralRe: Data from Scanner to Database Pin
Henry Minute23-Sep-09 8:31
Henry Minute23-Sep-09 8:31 
AnswerRe: Data from Scanner to Database Pin
cmk23-Sep-09 8:29
cmk23-Sep-09 8:29 
QuestionExcel Chart Secondary Axis Pin
Cwenee23-Sep-09 5:29
Cwenee23-Sep-09 5:29 
AnswerRe: Excel Chart Secondary Axis Pin
Qu Dong2-Sep-13 23:11
Qu Dong2-Sep-13 23:11 
QuestionXMLSerialization Pin
ahmedsamir23-Sep-09 3:21
ahmedsamir23-Sep-09 3:21 
AnswerRe: XMLSerialization Pin
stancrm23-Sep-09 3:40
stancrm23-Sep-09 3:40 
AnswerRe: XMLSerialization Pin
ahmedsamir23-Sep-09 13:07
ahmedsamir23-Sep-09 13:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.