Ejemplo n.º 1
0
        public new static SharepointDocumentLibraryItem Read(SharepointSession session, ObjectId objectId)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            SharepointDocumentLibraryItemId itemId = objectId as SharepointDocumentLibraryItemId;

            if (itemId == null)
            {
                throw new ArgumentException("objectId");
            }
            if (itemId.UriFlags != UriFlags.SharepointDocument && itemId.UriFlags != UriFlags.SharepointFolder)
            {
                throw new ArgumentException("objectId");
            }
            if (session.Uri != itemId.SiteUri)
            {
                throw new ObjectNotFoundException(itemId, Strings.ExObjectMovedOrDeleted(itemId.ToString()));
            }
            if (itemId.Cache != null && itemId.Cache.Value.Key == session.Identity.Name)
            {
                if (itemId.UriFlags == UriFlags.SharepointFolder)
                {
                    return(new SharepointDocumentLibraryFolder(itemId, session, itemId.Cache.Value.Value));
                }
                if (itemId.UriFlags == UriFlags.SharepointDocument)
                {
                    return(new SharepointDocument(itemId, session, itemId.Cache.Value.Value));
                }
            }
            return(Utils.DoSharepointTask <SharepointDocumentLibraryItem>(session.Identity, itemId, itemId, false, Utils.MethodType.Read, delegate
            {
                XmlNode nodeForItem = SharepointDocumentLibraryItem.GetNodeForItem(session, itemId);
                if (nodeForItem != null)
                {
                    SharepointList sharepointList = SharepointList.Read(session, new SharepointListId(itemId.ListName, itemId.SiteUri, null, UriFlags.SharepointDocumentLibrary));
                    itemId.Cache = new KeyValuePair <string, XmlNode>?(new KeyValuePair <string, XmlNode>(session.Identity.Name, nodeForItem));
                    itemId.CultureInfo = sharepointList.GetRegionalSettings();
                    if (itemId.UriFlags == UriFlags.SharepointFolder)
                    {
                        return new SharepointDocumentLibraryFolder(itemId, session, itemId.Cache.Value.Value);
                    }
                    if (itemId.UriFlags == UriFlags.SharepointDocument)
                    {
                        return new SharepointDocument(itemId, session, itemId.Cache.Value.Value);
                    }
                }
                throw new ObjectNotFoundException(itemId, Strings.ExObjectNotFound(itemId.ToString()));
            }));
        }
Ejemplo n.º 2
0
 public Stream GetDocument()
 {
     return(Utils.DoSharepointTask <Stream>(this.Session.Identity, base.Id, (SharepointSiteId)base.Id, true, Utils.MethodType.GetStream, delegate
     {
         Stream stream = null;
         HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.Uri);
         httpWebRequest.KeepAlive = false;
         httpWebRequest.Headers.Set("Pragma", "no-cache");
         httpWebRequest.Headers.Set("Depth", "0");
         httpWebRequest.ContentType = "text/xml";
         httpWebRequest.ContentLength = 0L;
         httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
         HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
         stream = httpWebResponse.GetResponseStream();
         bool flag = false;
         try
         {
             SharepointDocumentLibraryItemId sharepointDocumentLibraryItemId = (SharepointDocumentLibraryItemId)base.Id;
             XmlNode nodeForItem = SharepointDocumentLibraryItem.GetNodeForItem(this.Session, sharepointDocumentLibraryItemId);
             SharepointDocument sharepointDocument = new SharepointDocument(sharepointDocumentLibraryItemId, this.Session, nodeForItem);
             if (sharepointDocument.VersionControl.TipVersion != this.VersionControl.TipVersion)
             {
                 throw new DocumentModifiedException(base.Id, this.Uri.ToString());
             }
             flag = true;
         }
         finally
         {
             if (!flag)
             {
                 stream.Dispose();
                 stream = null;
             }
         }
         return stream;
     }));
 }