Example #1
0
        public HttpResponseMessage GetByAlternateField()
        {
            string authorizationString = DecodeAuthorizationString();

            SPHelper.SetSharePointCredentials(authorizationString);

            List <SharePointDocument> files = new List <SharePointDocument>();

            if (!string.IsNullOrEmpty(Request.RequestUri.Query))
            {
                List <KeyValuePair <string, string> > kvpList = Request.GetQueryNameValuePairs().ToList <KeyValuePair <string, string> >();

                string alternateFieldName = "", alternateFieldValue = "";
                foreach (KeyValuePair <string, string> kvp in kvpList)
                {
                    string key = kvp.Key;
                    string val = kvp.Value;

                    switch (key)
                    {
                    case "AlternateFieldName":
                        alternateFieldName = val;
                        break;

                    case "AlternateFieldValue":
                        alternateFieldValue = val;
                        break;

                    default:
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(alternateFieldName) && (!string.IsNullOrEmpty(alternateFieldValue)))
                {
                    ListItemCollection list = SPHelper.GetDocuments(alternateFieldName, alternateFieldValue);
                    if (list != null && list.AreItemsAvailable)
                    {
                        foreach (ListItem item in list)
                        {
                            SharePointDocument file = ListItemToSharePointDocument(item);
                            files.Add(file);
                        }
                    }
                }
            }
            else
            {
                // No Query String Included
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(JsonConvert.SerializeObject(files), Encoding.UTF8, "application/json");
            return(response);
        }