1

I was wondering if anyone could verify or see an error in this CAML query:

SPQuery query = new SPQuery();
                            query.Query = string.Format(
                                           "<Where>",
                                            "<Or>",
                                               "<Eq>",
                                                  "<FieldRef Name='ItemRedirectId'/>",
                                                  "<Value Type='Text'>{0}</Value>",
                                               "</Eq>",
                                               "<Eq>",
                                                  "<FieldRef Name='GF_UrlIdRedirection'/>",
                                                  "<Value Type='Text'>{0}</Value>",
                                               "</Eq>",
                                            "</Or>",
                                           "</Where>", RemoveCurlyBracket(RedirectionId));

                            query.ViewFields = string.Empty;
                            query.ViewFieldsOnly = true; 

I have been getting the System.Runtime.InteropServices.COMException (0x80004005): Cannot complete this action

I have been getting this error in the logs:

Microsoft.SharePoint.SPException: Cannot complete this action.

Please try again. ---> System.Runtime.InteropServices.COMException (0x80004005): Cannot complete this action.

Please try again. at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView) at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView) --- End of inner exception stack trace --- at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView) at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData() at Microsoft.SharePoint.SPListItemCollection.get_Count()

Based on what I was able to find online is that if this was a .net error I would be getting a much more specific answer in terms of what caused the error and that in most cases this error is caused by a bad CAML query, but i cannot find an issue with mine.

Any suggestions?

3

I think you have a mistake in code. Your string.Format returns only

  <where>

Try code below

query.Query = string.Format(string.Concat(
                                       "<Where>",
                                        "<Or>",
                                           "<Eq>",
                                              "<FieldRef Name='ItemRedirectId'/>",
                                              "<Value Type='Text'>{0}</Value>",
                                           "</Eq>",
                                           "<Eq>",
                                              "<FieldRef Name='GF_UrlIdRedirection'/>",
                                              "<Value Type='Text'>{0}</Value>",
                                           "</Eq>",
                                        "</Or>",
                                       "</Where>"), RemoveCurlyBracket(RedirectionId));
0
SPQuery query = new SPQuery();
                            query.Query = string.Format(@"<Where>
                                            <Or>
                                               <Eq>
                                                  <FieldRef Name='ItemRedirectId'/>
                                                  <Value Type='Text'>{0}</Value>
                                               </Eq>
                                               <Eq>
                                                  <FieldRef Name='GF_UrlIdRedirection'/>
                                                  <Value Type='Text'>{0}</Value>
                                               </Eq>
                                            </Or>
                                           </Where>", RemoveCurlyBracket(RedirectionId));

                            query.ViewFields = string.Empty;
                            query.ViewFieldsOnly = true; 

try the above method instead!

its still wrong tho! ill explain! firstly iv used @ so that you dont use , and you have it witin the "" allowing you to have multiple lines within the bracket ;). Secondly which i havent ammended is string.Format is used when you want to fill in areas that are varible! as an example:

int a = 2;
int b = 2;

string z = string.empty;

z = string.Format(@"a={0} and b={1} which gives an answer of 4",a,b);

so string.Format(text,varible,varible); , anywhere you put {0} is going to be filled up from the varible, i have two in my example {0} and {1} that get filled by a and b, so the output for z is:

a=2 and b=2 which gives an answer of 4

another example if i want to expand:

example:

int a = 2;
int b = 2;
int c = a * c;
string z = string.empty;

z = string.Format(@"here we are multiplying a and b, so if a={0} and b={1} which gives an answer of {2}",a,b,c);

result:

here we are multiplying a and b, so if a=2 and b=2 which gives an answer of 4

so in your example you have multiple , which is not correct and two {0} so even if you do use @ then both {0} will be filled from RemoveCurlyBracket(RedirectionId) method unless that is what you want??, it should be somthing like this:

string itemID = 1;
string UrlIdRedirection = "http://google.com";

SPQuery query = new SPQuery();
                            query.Query = string.Format(@"<Where>
                                            <Or>
                                               <Eq>
                                                  <FieldRef Name='ItemRedirectId'/>
                                                  <Value Type='Text'>{0}</Value>
                                               </Eq>
                                               <Eq>
                                                  <FieldRef Name='GF_UrlIdRedirection'/>
                                                  <Value Type='Text'>{1}</Value>
                                               </Eq>
                                            </Or>
                                           </Where>",itemID ,UrlIdRedirection );

                            query.ViewFields = string.Empty;
                            query.ViewFieldsOnly = true; 
  • lol why have i been marked down? this is correct! just becasue the excepted answer uses string.concat which is joing multiple strings of arrays from a comma. either way works!! you need to lookup on what concat does befor marking me down as this is more than a valid answer! the op was using string.Format so i explained why it wasnt working! – Ali Jafer Jan 13 '14 at 9:50
  • Ali, I didnt mark you down, i don't know who did, i marked VMAs answer as the correct one since using "@" can and will lead to performance issues. I have read your reply and found it interesting and informative (to some degree) and appreciate the effort you took responding to my inquiry. – Orbital Jan 13 '14 at 9:58
  • lol i know you didnt, thanks for telling me tho! im just supprised someone marked a valid answer that is correct without expaining why! glad you got your code working tho :) – Ali Jafer Jan 13 '14 at 10:03

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.