public ActionResult Logout() { _sPC = (SharePointConnect)Session["SPC"]; _sPC.DisposeSP(); Session.Remove("SPC"); return(RedirectToAction("LoginIndex")); }
public bool CheckSession() { if (Session["SPC"] == null) { return(false); } _sPC = (SharePointConnect)Session["SPC"]; return(true); }
public ActionResult Login(string email, string password, string url) { if (!url.Contains("https://")) { url = "https://" + url; } _sPC = new SharePointConnect(email, password, url); if (!_sPC.SaveContext()) { TempData["LoginFail"] = "Failed to login"; return(RedirectToAction("LoginIndex")); } Session["SPC"] = _sPC; return(RedirectToAction("Index")); }
public JsonResult DownloadReport(string jobNumber, string id, string documentName) { try { var folderName = jobNumber + "_" + id.Replace("-", "").ToUpper(); var context = SharePointConnect.GetClientContext(); if (context != null) { // Create CAML query to get Document var camlQry = @"<View> <Query> <Where> <Eq> <FieldRef Name='FileLeafRef' /> <Value Type='File'>" + folderName + @"</Value> </Eq> </Where> </Query> <ViewFields> <FieldRef Name='Title'/> <FieldRef Name='FileRef'/> </ViewFields> </View>"; CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = camlQry; // Add Query to Call for SharePoint List List lstDocument = context.Web.Lists.GetByTitle("Inspection Detail"); ListItemCollection lstDocumentDetail = lstDocument.GetItems(camlQuery); context.Load(lstDocumentDetail); context.ExecuteQuery(); if (lstDocumentDetail != null) { foreach (var lstItem in lstDocumentDetail) { var fileRef = lstItem["FileRef"]; var fullFilePath = fileRef.ToString() + "/" + documentName; FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, fullFilePath); using (var memory = new MemoryStream()) { //// Reading context of file into memoryStream byte[] buffer = new byte[1024 * 64]; int nread = 0; while ((nread = fileInfo.Stream.Read(buffer, 0, buffer.Length)) > 0) { memory.Write(buffer, 0, nread); } memory.Seek(0, SeekOrigin.Begin); // send the PDF file to browser byte[] byteArray = memory.ToArray(); var fileData = Convert.ToBase64String(byteArray); return(Json(fileData, JsonRequestBehavior.AllowGet)); } } } } return(null); } catch (Exception e) { return(null); } }