mshaji
asked on
Value does not fall in the expected range
I have SharePoint blog in English and Arabic language versions. By C# code i inserted successfully a new item to Blog post. But while I try to insert a new item in the Arabic version then its giving error: Value does not fall within the expected range.
Is there any setting I have to change in here. Please see my code here.
string DURL = "http://mysite/Arabic/Blog1/Lists/Posts/";
using (SPSite site = new SPSite(DURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Posts"];
SPUser user = web.EnsureUser(HttpContext .Current.U ser.Identi ty.Name);
SPListItem Item1 = list.Items.Add();
Item1["Title"] = TxtTitle.Text;
Item1["Body"] = TxtBody.Text;
Item1.Fields["Created By"].ReadOnlyField = false;
Item1["Published"] = System.DateTime.Now;
string userValue = user.ID + ";#" + user.Name;
Item1["Created By"] = userValue;
Item1.Update();
Item1.Fields["Created By"].ReadOnlyField = true;
}
}
Is there any setting I have to change in here. Please see my code here.
string DURL = "http://mysite/Arabic/Blog1/Lists/Posts/";
using (SPSite site = new SPSite(DURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Posts"];
SPUser user = web.EnsureUser(HttpContext
SPListItem Item1 = list.Items.Add();
Item1["Title"] = TxtTitle.Text;
Item1["Body"] = TxtBody.Text;
Item1.Fields["Created By"].ReadOnlyField = false;
Item1["Published"] = System.DateTime.Now;
string userValue = user.ID + ";#" + user.Name;
Item1["Created By"] = userValue;
Item1.Update();
Item1.Fields["Created By"].ReadOnlyField = true;
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mshaji, to close the question you need to identify which expert comment helped you solve your prolem, or if you solved it yourself you need to write a comment explaining what the solution was and accept your own comment as the answer.
ASKER
please close this
I recommend a split. 75% to Game-Master and 25% to Hairbrush for an assist.
(The need to use internal field names as explained by Games-Master is the most likely cause of the asker's problem, whereas my comment is more general best practice and would help track down the specific line that is causing a problem)
(The need to use internal field names as explained by Games-Master is the most likely cause of the asker's problem, whereas my comment is more general best practice and would help track down the specific line that is causing a problem)
ASKER