0

In my requirement i was added items in list through Timerjob.When Item was added in Event receiver get triggered.

My question is,

Getting resource file from virtual Directory App_GlobalResources the value is null.

But getting resource file from 15\Resources the value is coming.

In timer job it is not possible to get Resources File value from virtual Directory App_GlobalResources.

public override void Execute(Guid contentDbId) {

        string strUrl = string.Empty;
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                sbContractUpdate = new StringBuilder();
                sbContractadd = new StringBuilder();
                using (SPSite site = this.WebApplication.Sites[0])
                {
                    using (SPWeb currWeb = site.OpenWeb())
               {
                        string rvalue = objUtilities.GetResourceString("User_Name"); //this value from(C:\inetpub\wwwroot\wss\VirtualDirectories\2013\App_GlobalResources)
                       // rvalue is coming null.

                        string vall = objUtilities.GetListNameFromResource("User_Name", currWeb.Language);
                        //vall is coming User Name.
                        // vall resource path C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\Resources
                    }
                }
            }

Item added we are getting values from resource file.(C:\inetpub\wwwroot\wss\VirtualDirectories\1000\App_GlobalResources)Manually adding item to list resoure file value is coming in Itemadded.But through timer job if i added values to list resource file values are coming null.

How i can solve this ?

Mycode:

 public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);

       if (Convert.ToString(oListItem["Name"]) != objUtilities.GetResourceString("UserName"))
{

}

i attached OWSTIMER.EXE and debug here( objUtilities.GetResourceString("User_Entry")) the value is coming null

But if i attached W3wp.exe the value is coming.

So in timerjob how can i get the value of resource file.

1

As per your given code its Event Receiver not Timer Job Code.

Timer Job always inherit SPJobDefination Class.

Follow below article for Timer JOB:

https://msdn.microsoft.com/en-us/library/ff798313.aspx

Remember: After deployment of timer job require to restart timer service.

After that you may get resource file with owstimer.exe.

Thanks.

  • My code is event receiver only .When the Timerjob runs i will add some values to List. So before adding values Itemadded method get triggered.In that time resource file value is coming null. – elina Sep 29 '16 at 5:57
1

Timer Job will run at Web Application level so their privileges admin level when its adding item to list.

And when you are doing manually doing entry to list it's might different user.

So can you confirm Timer Job running with which user is same as manual entry user?

Example: In my case SharePoint Farm is running with Farm Account and my web application list is running with another user account.

enter image description here

So might be possible you are getting null values.

  • yes, My farm account is different,I login as different user.It is not possible to get Resource file from Virtual directory? – elina Sep 29 '16 at 7:27
  • Timer Job running with Farm account User. – elina Sep 29 '16 at 7:38
  • It is possible with Impersonate User concept but make sure that user has permission according to your requirement. If this solves make my answer as complete. – Prashant Shah Sep 29 '16 at 8:01
  • please can you elaborate how i can use Impersonate User concept – elina Sep 29 '16 at 10:07
  • sharepointdeveloperhq.com/2009/04/… See this example you may get some idea. After impersonating successfully you may not have null value. – Prashant Shah Sep 29 '16 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.