Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

How to get the state of the docuemnt whether it is locked or not in sP-2013?

$
0
0

I have document library with workflow attached with it.

There are metadata columns attached with the document library i.e. Test1 & Test2

I am modifying the value of the Test1 & Test2 in the console application for changes required. I can successfully change the value of the metadata columns in the console if the document is not opened, but if the document is opened then it throws the error that the document is already locked.

I want to catch the state of the document whether it is locked or not. If it is locked I want to give the message that the document is already locked you cannot update the metadata column. The reason behind of doing is that I have attached the workflow, if any error occurs the workflow will stop working.

My code for the console is:

class Program
    {
        static void Main(string[] args)
        {
            using (SPSite siteCollection = new SPSite(@"http://sp2013-15"))
            {
                using (SPWeb web = siteCollection.RootWeb)
                {
                    using (web)
                    {
                        try
                        {
                            SPList list = web.Lists["Documents"];
                            SPListItem item = list.Items[0];                            
                            item["TESt"] = "Managed";
                            item.Update();
                            Console.WriteLine("Changed");
                            Console.ReadKey();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.ReadKey();
                        }
                    }
                }

            }
        }
    }


Is there any property available for the ListItem to determine whether the item is locked or not?

What should I do to get idea of lock item?

Please help.



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>