1

I have some strange issue with server object model... I am creating timerjob, its has to just run item.update() function and rest of work is done by event receiver.

server url - demo2010a:2010

sitecolletion url - http://www.contoso.com/sites/test/

list url - http://www.contoso.com/sites/test/Lists/Zadania%20naprawcze%20t/

the problem is in:

        SPSite site = new SPSite("http://www.contoso.com/sites/test/");
        SPWeb web = site.OpenWeb("sites/test");

        SPList ldk_List = web.GetList("http://www.contoso.com/sites/test/Lists/Zadania naprawcze t"); //this is working fine ! but i cant use absolute URL !!!
        SPListItem item = ldk_List.GetItemById(5);
        item["Title"] = "testestestestes";
        item.Update();

this is my "Test" code. List name is "Zadania Naprawcze -t" in url its look strange but it is working with http://www.contoso.com/sites/test/Lists/Zadania naprawcze t i want something like : web.GetList("/sites/Zadania Naprawcze -t"); or something i tried to cut the - etc. could someone tell me what should to do? All the code is running as Timer Job.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sebastian 506563
  • 6,980
  • 3
  • 31
  • 56

1 Answers1

1

Your question isn't perfectly clear. "Lists/Zadania naprawcze t" works and is the URL of the list. "/Lists/Zadania%20naprawcze%20t/" is the same thing just encoded (%20 = space). Now you're asking about -t, where do you get the - from? There is a difference between list title and list url, you know that right? The GetList method requires you to provide the List URL, there also is the SPListCollection.TryGetList method which you could provide with the title of the list (web.lists.TryGetList()).

Dennis G
  • 21,405
  • 19
  • 96
  • 133
  • the name with list was created is "Zadania naprawcze -t". VS2010 show me tooltip to Web.GetList("") about SERVER RELATIVE URL maybe i am wrong what relavie mean but still "Lists/Zadania naprawcze t" is not working in example in my question – Sebastian 506563 Mar 06 '13 at 09:04
  • 1
    So you're actually asking about the *relative URL not working*? The URL needs to include the full path. `SPList ldk_List = web.GetList("/sites/test/Lists/Zadania naprawcze t");` should work. Or try `/test/Lists/Zadania...` – Dennis G Mar 06 '13 at 09:39
  • funny thing to say, but it is still not working. Absolute-Url work fine. This code is running as Timer Job, maybe this small information is important ? – Sebastian 506563 Mar 06 '13 at 10:31
  • Very important! The timer job can only run in the context of a content database, or in the context of a **web application** which I assume you are doing. Maybe the context is not set correctly for your web and hence the list cannot be retrieved. Try with simpler lists first, you are not using best practice anyways with your List URL having spaces. Your list URL should have no special characters - your list title can be anything yoU'd like. Also try the `TryGetList` method. – Dennis G Mar 06 '13 at 11:15
  • when i am creating lists the i do this witout space. You are right your code work fine in other context . Thnak u for help – Sebastian 506563 Mar 07 '13 at 08:43