0

I've a document library and i've to delete document to replace it by a link to an external url. So i thinked to add a content type "link to document" Make a script client to change content type of my items and add url and delete document but all the item is deleted

myCtxtWeb.Load(item);
                    myCtxtWeb.ExecuteQuery();

                    ContentTypeCollection listContentTypes = list.ContentTypes;
                    myCtxtWeb.Load(listContentTypes);
                    myCtxtWeb.ExecuteQuery();
                    var ctid = from ct in listContentTypes
                               where ct.Name == "LinkDoc"
                               select ct.Id;

                    item["ContentTypeId"] = ctid;
                    item["ows_URL"] = "http://www.google.be";
                    item.Update();
                    myCtxtWeb.Load(list);
                    myCtxtWeb.ExecuteQuery();

                    if (item["FileLeafRef"].ToString().Contains("test"))
                    {
                        myCtxtWeb.Load(item.File);
                        myCtxtWeb.ExecuteQuery();
                        item.File.DeleteObject();
                        myCtxtWeb.ExecuteQuery();
                    }

Are there a way to do this without created a new item?

0

In Document Library you need a file. That file can be associated to any content types (that are derived from Document).

In your case if you delete the file, the associated content type (as well as meta data) is lost.

You should look into creating a Custom List and then use that to link external files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.