Avatar of mshaji
mshajiFlag for India

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.User.Identity.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;
              }
            }
Microsoft SharePoint

Avatar of undefined
Last Comment
Hairbrush
SOLUTION
Avatar of Hairbrush
Hairbrush
Flag of Jersey image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of mshaji
mshaji
Flag of India image

ASKER

Closed
Avatar of Hairbrush
Hairbrush
Flag of Jersey image

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.
Avatar of mshaji
mshaji
Flag of India image

ASKER

please close this
Avatar of Hairbrush
Hairbrush
Flag of Jersey image

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)
Microsoft SharePoint
Microsoft SharePoint

Microsoft Sharepoint is a software platform and family of software products used for collaboration and web publishing combined. These capabilities include developing web sites, portals, intranets, content management systems, search engines, wikis, blogs, and other tools for business intelligence and collaboration. SharePoint has a Microsoft Office-like interface, and it is closely integrated with the Office suite.

40K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo