Monday, February 20, 2006

System.Runtime. InteropServices. COMException on viewlsts.aspx and SPWeb form context

Some time ago I was developing a web control which had to take a list of a SPListItems from a specific SPList from a current SPWeb. Simple thing. Code was also simple. I used SPControl.GetContextWeb and got the list I wanted. I wrote the code and everything was ok until… until during tests I got into a viewlsts.aspx page. This page welcomed me with a nasty error message:

System.Runtime.InteropServices.COMException

First thing that came to my mind was that the list was not found. Strange. That means that the list disappeared or the wrong SPWeb has been opened. To check it I printed the SPWeb.Url and SPWeb.Name properties. Url was ok, but the .Name was from totally different Web! That’s why the list couldn’t be found - SPControl.GetContextWeb opened some other Web.
Ok, ok. So let’s create SPWeb object manually. Dang, another problem. Page.Request.Url returns only "_layouts/1033/viewlsts.aspx". But hey, the .Url property of our ‘wrong’ SPWeb object from context is correct, so why not use it. That was it, now everything works like a charm :)

Here’s the code:



private SPWeb GetCurrentSPWeb()

{

    SPWeb contextWeb = SPControl.GetContextWeb(Context);

    SPSite site = new SPSite(contextWeb.Url);

 

    Uri contextWebUri = new Uri(contextWeb.Url);

 

    SPWeb currentWeb = site.OpenWeb( contextWebUri.AbsolutePath ) 

 

    return currentWeb;



The recommendation I’ve been told some time ago, says that it’s better to get the SPWeb from SPSite.OpenWeb and not from the context. As you can see recommendation is good because context sometimes doesn’t work like it should :)

Thursday, February 2, 2006

Curse you Visual Studio 2003!!

Since I'm working on VMWare machine on SharePoint, the little window named "Microsoft Development Environment has encountered a problem and needs to be close" become main part of my life.

Always when I got this message I had a close and send error to Microsoft buttons. I always send those error reports.

Few moments ago VS crashed again, but this time I got a window without the send button. What?, I guess the guys at Microsoft are just tired of those reports... just like we are tired of those crashes.

Check it out

  Visual Studio 2003 crash

[UPDATE 08 feb 2006]

wait, the 'send error' button is back. I still can spam Microsoft with my error reports :-)

Wednesday, February 1, 2006

Google toolbar 4 beta

Check it out. New version of Google Toolbar. It has a new looks. Take a look at it, maybe you will like it :-) It's still beta.

http://www.google.com/tools/toolbar/T4/index.html

Just found those cool things:
  • When you type text toolbar gives you suggestions and checks for typos
  • When you type text which is longer that a toolbar's textbox, it expands! that what I was missing. Now you can type long sentences and see it all.
So go ahead and download it, now! :-)