Unable to read from XML file in a SharePoint Timer Job -


i have custom timer job should read data xml file , save in word file. tested code in simple web part , works fine. not working custom timer job. here code -

public override void execute(guid targetinstanceid)     {         #if (debug)             system.diagnostics.trace.assert(false);         #endif           // reference current site collection's content database         spwebapplication webapplication = this.parent spwebapplication;         spcontentdatabase contentdb = webapplication.contentdatabases[targetinstanceid];           //define string builder object         stringbuilder stringbuilder = new system.text.stringbuilder();         //double revenue = 0;         //creating object of configuration class          //reading page size xml configuration file         int intpagelimit = weeklyconfig.readpagesize();         //reading column name xml configuration file         list<string> strlist = weeklyconfig.readcolumnname();         //reading list name xml configuration file         string strlistname = weeklyconfig.readlistname();         //reading library name xml          string strlibraryname = weeklyconfig.readlibraryname();         stringbuilder.append(intpagelimit);         foreach (string str in strlist)         {             stringbuilder.append(str);         }         stringbuilder.append(strlistname);         stringbuilder.append(strlibraryname);         spfolder customerdoclib = null;         customerdoclib = contentdb.sites[0].rootweb.folders["reports"];         byte[] bytearray = encoding.ascii.getbytes(stringbuilder.tostring());         memorystream stream = new memorystream(bytearray);         string filename = "testreport_" + datetime.now.tostring("mmddyyyyhhmmss") + ".doc";//creating .doc file         customerdoclib.files.add(filename, stream);//writing memory stream doc file , saving sharepoint document library     } 

here code creates xml file. have added code in event receiver @ feature level. i'm saving xml file in inetpub's virtual directory site collection deployed. path - c:/inetpub/wwwroot/wss/virtualdirectories/38118/configuration/configfile.xml

public static void createconfigfile(string path)     {         //use xml writer         using (xmlwriter writer = xmlwriter.create(path + "/configfile.xml"))         {             //start xml document             writer.writestartdocument();             //create root element             writer.writestartelement("root");             //write element in root element             writer.writeelementstring("pagesize", "33");             writer.writeelementstring("column", "title");             writer.writeelementstring("column", "salesperson");             writer.writeelementstring("column", "salestarget");             writer.writeelementstring("column", "achieved");             writer.writeelementstring("column", "unitprice");             writer.writeelementstring("column", "totalrevenue");             writer.writeelementstring("listname", "saleslist");             writer.writeelementstring("libraryname", "reports");             //end root element             writer.writeendelement();             //end xml document             writer.writeenddocument();         }        } 

these methods i'm using read xml file. these work totally fine webpart. gives exception "object reference not set instance of object" when used in timer job.

public class configuration : layoutspagebase {    public list<string> readcolumnname()     {         xmlreader reader = xmlreader.create(server.mappath("~/automatedreport/configfile.xml"));         list<string> listcolumnname = new list<string>();         string element = "";         while (reader.read())         {             if (reader.nodetype == xmlnodetype.element)             {                 element = reader.name;             }              else if (reader.nodetype == xmlnodetype.text)             {                 switch (element)                 {                     case "column": listcolumnname.add(reader.value.tostring());                         break;                 }             }         }         return listcolumnname;     } 

this 1 of methods i'm using read. reading column names of list.

the xml file generated properly. going wrong here?

save xml file in c:\program files\common files\microsoft shared\web server extensions\14 directory..... owstimer don't have access to
server.mappath("~/automatedreport/configfile.xml")


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -