?
Solved

'Microsoft.SharePoint.SPList.GetItemById(int)' has some invalid arguments

Posted on 2011-04-21
9
Medium Priority
?
1,810 Views
Last Modified: 2012-08-14
The error below points to this line in my code:

SPListItem item = sourceList.GetItemById(hdID);

error CS1502: The best overloaded method match for 'Microsoft.SharePoint.SPList.GetItemById(int)' has some invalid arguments

Any ideas.  See a piece of code below.


foreach (GridViewRow row in GridView1.Rows)
            {                         
                HiddenField hdID = (HiddenField)row.FindControl("hdID");
                CheckBox complete = (CheckBox)row.FindControl("complete");

                if (complete.Checked)
                {
                    msg.Text += "GRIDVIEW LOOP -- hdID #: " + hdID.Value + "<br />";

                        SPListItem item = sourceList.GetItemById(hdID);
                        byte[] fileBytes = item.File.OpenBinary();
                        string destUrl = destList.RootFolder.Url + "/" + item.File.Name;
                        SPFile destFile = destList.RootFolder.Files.Add(destUrl, fileBytes, true /*overwrite*/);
                    
  
                        SPListItem destItem = destFile.Item;
                        destItem["STATUS"] = "REROUTE";
                        destItem["CASE NUMBER"] = "CASE NUMBER";
                        destItem["PRIORITY"] = "Y";
                        destItem["PRIORITY CODE"] = "PRIORITY CODE";
                        destItem["COMPLETE"] = "YES";

                        destItem.Update();
                }
        }

Open in new window

0
Comment
Question by:Isaac
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35441901
hdID.Value
is acutaly a String

So you need to cast to an int

replace
SPListItem item = sourceList.GetItemById(hdID);

with

SPListItem item = sourceList.GetItemById(int.Parse(hdID));

Best of luck
0
 
LVL 5

Author Comment

by:Isaac
ID: 35442118
Now I get this error:

 error CS1502: The best overloaded method match for 'int.Parse(string)' has some invalid arguments  
 
 
0
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35442164
replace
SPListItem item = sourceList.GetItemById(hdID);

with

SPListItem item = sourceList.GetItemById(int.Parse(hdID.toString()));
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 5

Author Comment

by:Isaac
ID: 35442202
Now I get this error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Stack Trace:


[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471335
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
   System.Int32.Parse(String s) +23
   ASP._controltemplates_webusercontrol_ascx.Button1_Click(Object sender, EventArgs e) in c:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES\WebUserControl.ascx:60
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

 
0
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35442303
This means that your Grid does  not pass the value in that cell hdID


that could be a java scripting limiation .

I suggest you trace at this line and check the values at run time

Best of luck.
0
 
LVL 5

Author Comment

by:Isaac
ID: 35442711
GeorgeGerques,

I did a view source on the page before clicking submit and copied this piece of source code on one of the controls:

<input type="hidden" name="ctl00$m$g_8198334b_f124_40b9_a51e_787dd5b05a8d$ctl00$GridView1$ctl02$hdID" id="ctl00_m_g_8198334b_f124_40b9_a51e_787dd5b05a8d_ctl00_GridView1_ctl02_hdID" value="2" />

Am I writing the right code to retrieve "hdID"?
0
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35442736

replace
SPListItem item = sourceList.GetItemById(hdID);

with

SPListItem item = sourceList.GetItemById(int.Parse(hdID.Value.toString()));
0
 
LVL 5

Author Comment

by:Isaac
ID: 35442945
That did not work but this did,

SPListItem item = sourceList.GetItemById(Convert.ToInt32((hdID.Value)));

Thanks for leading me in the right direction.
0
 
LVL 14

Accepted Solution

by:
GeorgeGergues earned 2000 total points
ID: 35443062
SPListItem item = sourceList.GetItemById(Convert.ToInt32((hdID.Value)));

It is

Glad it worked.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question