Updating the Lstring UrlName field.

Posted by Community Admin on 04-Aug-2018 09:51

Updating the Lstring UrlName field.

All Replies

Posted by Community Admin on 30-May-2012 00:00

Hi, I have a custom module  and i am trying to add items to this module programatically.

1) Which are the mandatory fields that i need to fill ?
2) How do i update the Lstring field ie. the UrlName field.

Here is the sample code which i am using please corret me. and i am getting error when i update the field as "System.InvalidOperationException: Unsupported language "en". If you want to support this language, please configure your application accordingly."

Code :

 public string AddOrUpdateOffice(string xmlFullPath)
        
            Office objOffice = DeserializeOfficeFromXML(xmlFullPath);
 
            OfficesManager objOfficeManager = new OfficesManager();
            objOfficeManager.Provider.SuppressSecurityChecks = true;
            
            string urlname;
 
            OfficeItem objOfficeItem = objOfficeManager.GetOffices().Where(x => x.Code == objOffice.Code).FirstOrDefault();
            if (objOfficeItem == null)
            
                OfficeItem objNewOfficeItem = objOfficeManager.CreateOffice(new Guid());
                objNewOfficeItem.Code = objOffice.Code;
                objNewOfficeItem.ApplicationName = objOffice.Name;
                objNewOfficeItem.Email = objOffice.Email;
                
                objNewOfficeItem.Fax = objOffice.Fax;
                objNewOfficeItem.StreetAddress = objOffice.Address;
                objNewOfficeItem.PostalCode = objOffice.Postcode;
                objNewOfficeItem.PostOffice = objOffice.PostOffice;
                objNewOfficeItem.BusinessHours = objOffice.Businesshours;
                objNewOfficeItem.Latitude = Convert.ToString(objOffice.X);
                objNewOfficeItem.Longitude = Convert.ToString(objOffice.Y);
                objNewOfficeItem.BusinessProperties = Convert.ToString(objOffice.BusinessProperties);
                objNewOfficeItem.OpenPositions = Convert.ToString(objOffice.OpenPositions);
                objNewOfficeItem.AdministrationOffice = Convert.ToString(objOffice.AdministrationOffice);
                objNewOfficeItem.RentalOffice = Convert.ToString(objOffice.RentalOffice);
                objNewOfficeItem.Company = objOffice.Company;
                // Mandatory fields
                objNewOfficeItem.UIStatus = Telerik.Sitefinity.GenericContent.Model.ContentUIStatus.Published;                
                objNewOfficeItem.PublicationDate = DateTime.UtcNow;
                objNewOfficeItem.DateCreated = DateTime.Now;
                objNewOfficeItem.LastModified = DateTime.Now;
                urlname = objOffice.Name.ToLower();
 // Getting error while updating urlname field, the line below
                objNewOfficeItem.UrlName.SetStringNoFallback(new CultureInfo("en"false), Regex.Replace(urlname, @"[^\w\-\!\$\'\(\)\=\@\d_]+""-"));
                objNewOfficeItem.Status = Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master;
                objOfficeManager.Publish(objNewOfficeItem);
                
                objOfficeManager.SaveChanges();
 
                return "Office item added and published successfully.";
            

Posted by Community Admin on 03-Aug-2012 00:00

Hi Santhosh,

Its little bit late response but will be useful for others.

I also faced same issue when I was creating item with passing GUID in the createitem function. e.g

OfficeItem objNewOfficeItem = objOfficeManager.CreateOffice(new Guid());

But When I created item without passing GUID then It worked.
e.g
OfficeItem objNewOfficeItem = objOfficeManager.CreateOffice();


Regards,
Waqar

Posted by Community Admin on 10-Dec-2014 00:00

[quote]

OfficeItem objNewOfficeItem = objOfficeManager.CreateOffice(new Guid());

But When I created item without passing GUID then It worked.
e.g
OfficeItem objNewOfficeItem = objOfficeManager.CreateOffice();


Regards,
Waqar
[/quote]

 

Thanks Waqar!

 Two and a half years later, this is still confusing and a pain!  Telerik posts such great examples in blogs and such that give you 95% of the answer, and yet leave you dangling with these silly little issues that make no sense whatsoever.

 Bottom line, don't create ANY Sitefinity Object (in my case it was a BlogPost, rather than OfficeItem) passing in an initializing ID (Guid), let it create it's own, or your LStrings will be a bear to work with.
<Shakes Head>

This thread is closed