Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a code where I want to debug that why it cannot open the subsite, however in quickwatch window it opens it fine by doing "site.openweb(str[1])"

My code below (where str[0] has the server name and str[1] has subsite name):

SPWeb spwebdest = null;
            SPSite site = null;
            try
            {
                SPListItem spitem = workflowProperties.Item;
                string[] str = workflowProperties.AssociationData.Split(',');
                string Listtitle = spitem.ParentList.Title;


                if (!string.IsNullOrEmpty(str[1]))
                {
                    spwebdest = new SPSite("http://" + str[0]).OpenWeb(str[1]);
                }
                else
                {
                    site = new SPSite("http://" + str[0]);
                    spwebdest = site.RootWeb;
                }


                SPList list = spwebdest.Lists[str[2]];
                SPListItemCollection itemcoll = list.GetItems(new SPQuery()
                {
                    Query = @"<Where>
                <Eq>
                   <FieldRef Name='Title' />
                   <Value Type='Text'>" + spitem.Title + "</Value></Eq></Where>"
                });

Need help

Thanks.

share|improve this question
    
what exception you get? –  Amit Kumawat Feb 15 '12 at 15:56
    
could you elaborate on the 3 lines of your code at the beginning of the 'try' block - regarding 'workflowProperties' ? –  Supriyo SB Chatterjee Feb 15 '12 at 19:31
    
I m writing a custom workflow –  RHM Feb 15 '12 at 20:16
    
Getting no exception just the open web line isnt getting hit –  RHM Feb 15 '12 at 20:17
add comment

2 Answers

It looks like your str[1] value is an empty string.

If you are able to the use the 'site' object then you're getting into the 'else' portion of your if statement. That's only place it's being set.

Calling SPSite.OpenWeb() with an empty string, site.OpenWeb(""), will still give you the root web.

I would take at what is contained in your str array after you split the AssociationData.

share|improve this answer
    
It contains comma seperated values like e.g: servername, subsitename, listname –  RHM Feb 16 '12 at 8:20
    
I have checked it by debugging the code, the value in str[1] is the subsites name and in quick watch it works fine but while debugging I can see that when it reaches the breakpoint of site.OpenWeb(str[1]) it just skips that line and moves to the code below it. –  RHM Feb 16 '12 at 8:22
add comment

you have open the subsite from created site.

from the above example you have to write the code as

SPSite spwebdest=null; SPWeb currentWeb=null; if (!string.IsNullOrEmpty(str[0])) { spwebdest = new SPSite("http://" + str[0]); if (!string.IsNullOrEmpty(str[1])) { currentWeb=spwebdest.OpenWeb(str[1])) }
}

if it not worked you have to check string values giving corrct url or not.

Simple Suggestion: When ever you are opening a site or web you have to dispose them after using them. you have to use "Using" or "spsite.Dispose()"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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