internal void CheckInOut(bool checkIn, ProductPage.LicInfo li, SPList list, SPFolder folder, ref SPFile file, string fixedFileName, bool autoCheckOut, string autoCheckIn, string helpResName) { if (checkIn && list.ForceCheckout && !string.IsNullOrEmpty(autoCheckIn)) { if (!ProductPage.LicEdition(SPContext.Current, li.dic, 2)) { throw new Exception(ProductPage.GetProductResource("LicCheckInOut") + " " + ProductPage.GetProductResource(helpResName)); } else { file.CheckIn("Auto Check-In by UploadZen", (SPCheckinType)Enum.Parse(typeof(SPCheckinType), autoCheckIn, true)); } } else if ((!checkIn) && autoCheckOut && list.ForceCheckout) { try { if (file == null) { file = folder.Files [fixedFileName]; } } catch { } if (!ProductPage.LicEdition(SPContext.Current, li.dic, 2)) { throw new Exception(ProductPage.GetProductResource("LicCheckInOut") + " " + ProductPage.GetProductResource(helpResName)); } else if ((file != null) && file.Exists && ((file.CheckOutStatus == SPFile.SPCheckOutStatus.None) || (file.CheckedOutBy == null) || (file.CheckedOutBy.ID != SPContext.Current.Web.CurrentUser.ID) || (ProductPage.LoginName(file.CheckedOutBy.LoginName) != ProductPage.LoginName(SPContext.Current.Web.CurrentUser.LoginName)))) { file.CheckOut(); } } if (delay > 0) { Thread.Sleep(TimeSpan.FromSeconds(delay)); } }
public string UploadDocument(string fileName, Stream fileData, string folderName, bool unzip, bool overwrite, string autoCheckIn, bool autoCheckOut, string replace, byte [] metaDataRaw, bool hasHelp) { SPFolder folder, subFolder; SPFile file; ProductPage.LicInfo li = ProductPage.LicInfo.Get(null); Dictionary <string, Dictionary <string, string> > metaData = null; Dictionary <string, string> metaBag; SPList list; string [] folderPath = folderName.Split(new char [] { '/' }, StringSplitOptions.RemoveEmptyEntries); string fullPath, messages = string.Empty, ext = (fileName.Contains(".") ? fileName.Substring(fileName.LastIndexOf('.')) : string.Empty), helpResName = hasHelp ? "LicHelp" : "LicNoHelp"; int diff; for (int i = 0; i < folderPath.Length; i++) { if (folderPath [i].Length > 128) { folderPath [i] = folderPath [i].Substring(0, 128); } } folderName = string.Join("/", folderPath); if (!int.TryParse(ProductPage.Config(ProductPage.GetContext(), "UploadDelay"), out delay)) { delay = 0; } else { delay = Math.Abs(delay); } if ((metaDataRaw != null) && (metaDataRaw.Length > 0)) { metaData = roxority.Shared.SharedUtil.DeserializeBinary(metaDataRaw) as Dictionary <string, Dictionary <string, string> >; } if (!ProductPage.isEnabled) { using (SPSite adminSite = ProductPage.GetAdminSite()) throw new Exception(ProductPage.GetResource("NotEnabledPlain", ProductPage.MergeUrlPaths(adminSite.Url, "/_layouts/roxority_UploadZen.aspx?cfg=enable"), "UploadZen")); } if (li.userBroken) { throw new Exception(ProductPage.GetResource("LicExpiryUsers") + " " + ProductPage.GetProductResource(helpResName)); } else if (li.expired) { throw new Exception(ProductPage.GetResource("LicExpiry") + " " + ProductPage.GetProductResource(helpResName)); } //else if (string.IsNullOrEmpty (li.name) || (li.maxUsers < 0) || ((!string.IsNullOrEmpty (li.name)) && (li.maxUsers > 0) && (li.maxUsers <= 20))) { // if (unzip) { // unzipCounts [Context.Request.UserHostAddress] = unzipCounts.TryGetValue (Context.Request.UserHostAddress, out count) ? (++count) : (count = 1); // if (count > ProductPage.l2) // throw new Exception (ProductPage.GetProductResource ("LicTrial", ProductPage.l3, ProductPage.l2) + " " + ProductPage.GetProductResource (helpResName)); // } else { // counts [Context.Request.UserHostAddress] = counts.TryGetValue (Context.Request.UserHostAddress, out count) ? (++count) : (count = 1); // if (count > ProductPage.l3) // throw new Exception (ProductPage.GetProductResource ("LicTrial", ProductPage.l3, ProductPage.l2) + " " + ProductPage.GetProductResource (helpResName)); // } //} if (unzip && !ProductPage.LicEdition(SPContext.Current, li.dic, 4)) { throw new Exception(ProductPage.GetProductResource("LicUnzip") + " " + ProductPage.GetProductResource(helpResName)); } if ((!(Context.Request.LogonUserIdentity is WindowsIdentity)) && !ProductPage.LicEdition(SPContext.Current, li.sd, 4)) { throw new Exception(ProductPage.GetProductResource("LicForms") + " " + ProductPage.GetProductResource(helpResName)); } if ((metaData != null) && (metaData.Count > 0) && !ProductPage.LicEdition(SPContext.Current, li.sd, 4)) { throw new Exception(ProductPage.GetProductResource("LicMetaData") + " " + ProductPage.GetProductResource(helpResName)); } FixName(ref fileName); fileName = FixName(fileName, replace); if (fileName.Length > 128) { fileName = fileName.Substring(0, 128 - ext.Length) + ext; } using (SPWeb web = SPControl.GetContextWeb(HttpContext.Current)) { web.AllowUnsafeUpdates = true; fullPath = ('/' + folderName.Trim('/') + '/' + fileName); //ProductPage.MergeUrlPaths (web.Url, folderName.Trim ('/') + '/' + fileName); if (((diff = 260 - fullPath.Length) < 0) && ((diff = Math.Abs(diff)) < (fileName.Length - ext.Length))) { fileName = fileName.Substring(0, ext.Length + diff) + ext; } //if ((('/' + folderName.Trim ('/') + '/').Length < 260) && ((diff = 260 - ('/' + folderName.Trim ('/') + '/' + fileName).Length) < 0)) // fileName = fileName.Substring (0, ext.Length + Math.Abs (diff)) + ext; if (((folder = GetFolder(web, folderPath, replace)) == null) || ((list = web.Lists [folder.ParentListId]) == null)) { throw new FileNotFoundException(new FileNotFoundException().Message, string.Join("/", folderPath)); } if (!unzip) { file = null; CheckInOut(false, li, list, folder, ref file, fileName, autoCheckOut, autoCheckIn, helpResName); file = folder.Files.Add(fileName, fileData, overwrite || (list.ForceCheckout && autoCheckOut)); if (delay > 0) { Thread.Sleep(TimeSpan.FromSeconds(delay)); } CheckInOut(true, li, list, folder, ref file, fileName, autoCheckOut, autoCheckIn, helpResName); if (metaData != null) { foreach (KeyValuePair <string, Dictionary <string, string> > kvp in metaData) { SetMetaData(file.Item, kvp.Value, ref messages); break; } } } else { using (ZipFile zipFile = ZipFile.Read(fileData)) foreach (ZipEntry zipEntry in zipFile) { try { folderPath = zipEntry.FileName.Replace('\\', '/').Split(new char [] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (zipEntry.IsDirectory) { subFolder = GetFolder(web, folderName.Trim('/') + '/' + string.Join("/", folderPath), replace); if ((metaData != null) && metaData.TryGetValue(zipEntry.FileName, out metaBag)) { SetMetaData(subFolder.Item, metaBag, ref messages); } } else { using (MemoryStream ms = new MemoryStream()) { file = null; zipEntry.Extract(ms); fileName = zipEntry.FileName.Substring(zipEntry.FileName.LastIndexOf('/') + 1); FixName(ref fileName); fileName = FixName(fileName, replace); ext = (fileName.Contains(".") ? fileName.Substring(fileName.LastIndexOf('.')) : string.Empty); if (fileName.Length > 128) { fileName = fileName.Substring(0, 128 - ext.Length) + ext; } fullPath = folderName.Trim('/') + '/' + zipEntry.FileName.TrimStart('/'); //ProductPage.MergeUrlPaths (web.Url, folderName.Trim ('/') + '/' + fileName); if (((diff = 260 - fullPath.Length) < 0) && ((diff = Math.Abs(diff)) < (fileName.Length - ext.Length))) { fileName = fileName.Substring(0, ext.Length + diff) + ext; } CheckInOut(false, li, list, folder, ref file, fileName, autoCheckOut, autoCheckIn, helpResName); file = ((folderPath.Length == 1) ? folder : GetFolder(web, folderName.Trim('/') + '/' + zipEntry.FileName.Substring(0, zipEntry.FileName.LastIndexOf('/')).Trim('/'), replace)).Files.Add(fileName, ms.ToArray(), overwrite || list.ForceCheckout); if (delay > 0) { Thread.Sleep(TimeSpan.FromSeconds(delay)); } CheckInOut(true, li, list, folder, ref file, fileName, autoCheckOut, autoCheckIn, helpResName); if ((metaData != null) && metaData.TryGetValue(zipEntry.FileName, out metaBag)) { SetMetaData(file.Item, metaBag, ref messages); } } } } catch (Exception ex) { messages += (zipEntry.FileName + ": " + (ErrorDetails ? ex.ToString() : ex.Message) + "\r\n\r\n"); } } } } return(messages); }
protected override void CreateChildControls() { string wpPageUrl, otherPartID = Request.QueryString ["wpid"], viewRawID, tmpCssClass = "c" + ProductPage.GuidLower(Guid.NewGuid(), false), propVal, nuPropVal, srcPageUrl = string.Empty; ProductPage.LicInfo li = ProductPage.LicInfo.Get(null); bool hasInvalidParams = false, isInvalidParam, isB = ProductPage.LicEdition(ctx, li, 2); int itemID = 0; object sm; XmlElement elem; Panel panel = HeaderWebParts; ArrayList filters = null; Hashtable fht = null; Guid viewID = Guid.Empty; SPLimitedWebPartManager wpMan = null; List <SystemWebPart> parts = new List <SystemWebPart> (); List <string> queryString = new List <string> (); TitleBarWebPart tbwp; SystemWebPart pwp; ctx = ProductPage.GetContext(); foreach (string k in Request.QueryString.AllKeys) { if (!string.IsNullOrEmpty(k)) { if (!(isInvalidParam = (k.StartsWith("FilterField", StringComparison.InvariantCultureIgnoreCase) || k.StartsWith("FilterValue", StringComparison.InvariantCultureIgnoreCase)))) { if (!isB) { foreach (string [] arr in new string [] [] { PrintZenMenuItem.CalendarParams, PrintZenMenuItem.FolderParams, PrintZenMenuItem.PageParams, PrintZenMenuItem.SortParams }) { if (isInvalidParam = (Array.IndexOf <string> (arr, k) >= 0)) { break; } } } } if (isInvalidParam) { hasInvalidParams = true; } else { queryString.Add(k + "=" + Server.UrlEncode(Request.QueryString [k])); if ((!"rpzopt".Equals(k, StringComparison.InvariantCultureIgnoreCase)) && !"r".Equals(k, StringComparison.InvariantCultureIgnoreCase)) { PhVals ["QueryString_" + k] = Request.QueryString [k]; } } } } if ((!string.IsNullOrEmpty(Request.QueryString ["t"])) && (Title != Request.QueryString ["t"])) { Title = Request.QueryString ["t"]; } if (hasInvalidParams) { Response.Redirect(Request.RawUrl.Substring(0, Request.RawUrl.IndexOf('?')) + "?" + string.Join("&", queryString.ToArray()), true); } else if (!ProductPage.isEnabled) { MainWebPart.Controls.Add(new LiteralControl(ProductPage.GetResource("NotEnabled", "", ProductPage.GetTitle()))); } else { if ((!string.IsNullOrEmpty(viewRawID = Request.QueryString ["View"])) && !int.TryParse(viewRawID, out itemID)) { viewID = ProductPage.GetGuid(viewRawID); } if (ProductPage.LicEdition(ctx, li, 4)) { if (!string.IsNullOrEmpty(Request.QueryString ["fs"])) { filters = JSON.JsonDecode(Request.QueryString ["fs"]) as ArrayList; } if (!string.IsNullOrEmpty(Request.QueryString ["fj"])) { fht = JSON.JsonDecode(Request.QueryString ["fj"]) as Hashtable; } } foreach (IDictionary action in Actions) { if (Request.QueryString ["a"].Equals(action ["id"])) { try { if ((action ["sm"] is bool) && (bool)action ["sm"]) { if (!exAsmTried) { exAsmTried = true; try { exRefl = new Reflector(exAsm = Assembly.Load("System.Web.Extensions, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")); exType = exAsm.GetType("System.Web.UI.ScriptManager", false, true); } catch { } } if ((exRefl != null) && (exType != null) && (Form != null) && ((sm = exRefl.Call(exType, "GetCurrent", this)) == null)) { theLit.Controls.AddAt(0, (sm = exRefl.New(exType.FullName)) as Control); } } PhVals ["List_Title"] = string.Empty; PhVals ["Item_Title"] = string.Empty; PhVals ["View_Title"] = string.Empty; PhVals ["Context_Title"] = string.Empty; foreach (DictionaryEntry prop in action) { if (prop.Value is string) { PhVals ["PrintAction_" + prop.Key] = prop.Value + string.Empty; } } AutoPrint = PrintZenMenuItem.GetBool(action, "dp"); ShowPlaceholders = PrintZenMenuItem.GetBool(action, "sp"); ShowToolbar = PrintZenMenuItem.GetBool(action, "tb"); site = new SPSite(ctx.Site.ID); web = site.OpenWeb(ctx.Web.ID); if ((!string.IsNullOrEmpty(wpPageUrl = (action ["wp"] + string.Empty))) && ProductPage.LicEdition(ctx, li, 4)) { try { if ((wpPageUrl.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase) || wpPageUrl.StartsWith("https:", StringComparison.InvariantCultureIgnoreCase)) && !wpPageUrl.StartsWith(web.Url.TrimEnd() + '/', StringComparison.InvariantCultureIgnoreCase)) { site2 = new SPSite(wpPageUrl); web2 = site2.OpenWeb(); } if ((wpMan = ((web2 == null) ? web : web2).GetLimitedWebPartManager(wpPageUrl, PersonalizationScope.Shared)) == null) { throw new Exception("xyz"); } } catch (Exception ex) { Errors.Add(new Exception(ProductPage.GetProductResource("WebPartPageNotFound", wpPageUrl.ToUpperInvariant()), "xyz".Equals(ex.Message) ? null : ex)); } } if (!isB) { panel.Controls.Add(new LiteralControl("<div class=\"" + tmpCssClass + "\">Powered by <b>SharePoint-Tools.net/PrintZen</b></div><style type=\"text/css\"> ." + tmpCssClass + " { text-align: center; font-size: " + new Random().Next(24, 37) + "px; display: none; padding-bottom: 12px; } @media print { div." + tmpCssClass + " { display: block !important; } } </style>")); } if (wpMan == null) { if (!string.IsNullOrEmpty(otherPartID)) { AddOtherWebPart(Request.QueryString ["l"], otherPartID); } else if (itemID > 0) { AddListFormWebPart(action, itemID); } else if (Guid.Empty.Equals(viewID) && !string.IsNullOrEmpty(viewRawID)) { if (isB) { AddPeopleWebPart(action, viewRawID, filters, fht); } } else { AddListViewWebPart(action, viewID, filters, fht); } } else { Placeholders = true; foreach (SystemWebPart wp in ProductPage.TryEach <SystemWebPart> (wpMan.WebParts, false, delegate(Exception ex) { Errors.Add(ex); }, true)) { if ((tbwp = wp as TitleBarWebPart) == null) { parts.Add(wp); } else { PhVals ["TitleBar_Caption"] = tbwp.HeaderCaption; PhVals ["TitleBar_Description"] = tbwp.HeaderDescription; PhVals ["TitleBar_Image"] = tbwp.Image; PhVals ["TitleBar_Title"] = tbwp.HeaderTitle; if (PrintZenMenuItem.GetBool(action, "st")) { parts.Add(tbwp); } } } parts.Sort((wp1, wp2) => { return(wp1.ZoneIndex.CompareTo(wp2.ZoneIndex)); }); foreach (SystemWebPart wp in parts) { if (("PRINTZEN_LIST_VIEW".Equals(wp.Title.Trim(), StringComparison.InvariantCultureIgnoreCase)) || ("PRINTZEN_TARGET".Equals(wp.Title.Trim(), StringComparison.InvariantCultureIgnoreCase))) { if (!string.IsNullOrEmpty(otherPartID)) { AddOtherWebPart(Request.QueryString ["l"], otherPartID); } else if (itemID > 0) { AddListFormWebPart(action, itemID); } else if (Guid.Empty.Equals(viewID) && !string.IsNullOrEmpty(viewRawID)) { if (isB) { AddPeopleWebPart(action, viewRawID, filters, fht); } } else { AddListViewWebPart(action, viewID, filters, fht); } panel = FooterWebParts; } else { try { InitWebPart(wp); panel.Controls.Add(wp); } catch (Exception ex) { Errors.Add(ex); } } } foreach (Panel p in new Panel [] { HeaderWebParts, MainWebPart, FooterWebParts }) { foreach (Control ctl in p.Controls) { if ((pwp = ctl as SystemWebPart) != null) { foreach (PropertyInfo propInfo in pwp.GetType().GetProperties()) { if (propInfo.CanRead && propInfo.CanWrite) { if (propInfo.PropertyType == typeof(string)) { try { propVal = propInfo.GetValue(pwp, null) as string; } catch { propVal = null; } if ((!string.IsNullOrEmpty(propVal)) && (propVal != (nuPropVal = Replace(propVal)))) { propInfo.SetValue(pwp, nuPropVal, null); } } else if (propInfo.PropertyType == typeof(XmlElement)) { try { elem = propInfo.GetValue(pwp, null) as XmlElement; } catch { elem = null; } if ((elem != null) && Replace(elem)) { try { propInfo.SetValue(pwp, elem, null); } catch { } } } } } } } } } break; } catch (Exception ex) { Errors.Add(ex); break; } } }
internal static string PrepareUrl(SPContext ctx, HttpContext context, IDictionary action, SPWeb web, SPList list) { ProductPage.LicInfo li = ProductPage.LicInfo.Get(null); return("/_layouts/roxority_UploadZen/help/app/roxUp.application?cl=" + Gb(action, "cl", true) + "&w=" + ((SPSecurity.AuthenticationMode == AuthenticationMode.Windows) ? 1 : 0) + "&cf=" + Gb(action, "cf", true) + "&z=" + action ["uz"] + "&c=" + Gb(action, "sc", true) + "&d=" + (GetBool(action, "rp", true) ? 0 : 1) + "&l=" + context.Server.UrlEncode(list.RootFolder.Url) + "&f=" + context.Server.UrlEncode(GetFolderPath(ctx, context, list)) + "&s=" + context.Server.UrlEncode(web.Url) + "&t=" + context.Server.UrlEncode(web.Title) + "&hl=" + (((!GetBool(action, "sl", true)) && ProductPage.LicEdition(SPContext.Current, li, 2)) ? 1 : 0) + "&hh=" + (((!GetBool(action, "sh", true)) && ProductPage.LicEdition(SPContext.Current, li, 2)) ? 1 : 0) + "&ht=" + (GetBool(action, "st", true) ? 0 : 1) + "&li=" + (li.expired ? "x" : (ProductPage.LicEdition(SPContext.Current, li, 4) ? "u" : (ProductPage.LicEdition(SPContext.Current, li, 2) ? "b" : "l"))) + "&hn=" + (ProductPage.Config <bool> (SPContext.Current, "HideNote") ? 1 : 0) + "&u="); }
public static void Export(TextWriter writer, ICollection <IDictionary> allActions, string webUrl, string exportListID, string ruleID, string listViewID, string separator, string unixFlag, string fs, int min, string fj) { string locale = string.Empty, viewXml, sep = ",", versioning, colVal, subVersion, colName, verVal, newVerVal, tmp, fieldName, rollJson = null, mulSep = ProductPage.Config(ProductPage.GetContext(), "MultiSep"), acsep; string [] listColumns; int pos, verIndex = -1, theEnc; bool expGrps = false, versionRows = false, skipRow = false, isRoll, is2, is4, isMin; object val; HttpContext context = null; Encoding encoding = Encoding.Default; SPList exportList = null; SPListItemCollection listItems = null; SPView listView = null; SPField field; SPQuery query; List <SPListItemVersion> versions; Dictionary <string, string> verVals; ProductPage.LicInfo li = ProductPage.LicInfo.Get(null); ArrayList filters = null; SPView defView; Hashtable fht = null, rollOpt = null; XmlDocument doc = new XmlDocument(); XmlNode node; Action <string, string> csvWrite = null; IDictionary action = null; Guid ruleGuid, instGuid; List <string> originalViewFields; is2 = ProductPage.LicEdition(ProductPage.GetContext(), li, 2); is4 = ProductPage.LicEdition(ProductPage.GetContext(), li, 4); isMin = ProductPage.LicEdition(ProductPage.GetContext(), li, min); try { context = HttpContext.Current; } catch { } if (isRoll = ((context != null) && (context.Request != null) && (context.Request.QueryString != null) && !string.IsNullOrEmpty(rollJson = context.Request.QueryString ["rpzopt"]))) { rollOpt = JSON.JsonDecode(rollJson) as Hashtable; } if (li.expired) { throw new SPException(ProductPage.GetResource("LicExpiry")); } if (!isMin) { throw new SPException(ProductPage.GetResource("NopeEd", "ExportZen.exe", "Ultimate")); } using (SPSite site = new SPSite(webUrl)) using (SPWeb exportWeb = site.OpenWeb()) { if ((!isRoll) && (string.IsNullOrEmpty(exportListID) || ((exportList = exportWeb.Lists [new Guid(exportListID)]) == null))) { throw new SPException(ProductPage.GetProductResource("Old_NoExportList")); } foreach (IDictionary inst in allActions) { if (ruleID.Equals(inst ["id"] + string.Empty, StringComparison.InvariantCultureIgnoreCase) || ruleID.Equals(inst ["name"] + string.Empty, StringComparison.InvariantCultureIgnoreCase) || ((!Guid.Empty.Equals(instGuid = ProductPage.GetGuid(inst ["id"] + string.Empty))) && (!Guid.Empty.Equals(ruleGuid = ProductPage.GetGuid(ruleID))) && ruleGuid.Equals(instGuid))) { action = inst; break; } } if (action == null) { throw new SPException(ProductPage.GetProductResource("Old_NoRuleItem", ruleID, allActions.Count, ProductPage.LoginName(exportWeb.CurrentUser.LoginName), ProductPage.Config(ProductPage.GetContext(), "_lang"))); } if (is4 && (exportList != null) && !string.IsNullOrEmpty(listViewID)) { try { listView = exportList.Views [new Guid(listViewID)]; } catch { } } if (((listColumns = (action ["cols"] + string.Empty).Split(new string [] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)) == null) || (listColumns.Length == 0)) { if (isRoll) { listColumns = HttpUtility.UrlDecode(((((int)rollOpt ["nm"]) != 0) ? (DataSource.SCHEMAPROP_PREFIX + DataSource.SCHEMAPROP_TITLEFIELD + ":" + ProductPage.GetResource("Name") + "\r\n") : string.Empty) + rollOpt ["pr"] + "").Split(new char [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); } else if (exportList != null) { if ((defView = listView) == null) { defView = exportList.DefaultView; } originalViewFields = new List <string> (defView.ViewFields.Count); foreach (string fn in defView.ViewFields) { if ((Array.IndexOf <string> (ProductPage.SPOddFieldNames, fn) < 0) || fn.StartsWith("Link")) { originalViewFields.Add(fn + (((field = ProductPage.GetField(exportList, fn)) == null) ? string.Empty : (":" + field.Title))); } } listColumns = originalViewFields.ToArray(); } } if ((listColumns.Length > 3) && !is2) { listColumns = new string [] { listColumns [0], listColumns [1], listColumns [2] } } ; versionRows = (((val = action ["vhrows"]) is bool) && (bool)val); if (!string.IsNullOrEmpty(versioning = (action ["vhcol"] + string.Empty).Trim())) { for (int i = 0; i < listColumns.Length; i++) { if ("roxVersion".Equals((string.Empty + listColumns [i]).Trim(), StringComparison.InvariantCultureIgnoreCase)) { verIndex = i; break; } } if (verIndex < 0) { Array.Resize <string> (ref listColumns, listColumns.Length + 1); listColumns [verIndex = (listColumns.Length - 1)] = versioning; } else { listColumns [verIndex] = versioning; } } try { locale = action ["loc"] + string.Empty; } catch { } try { if (!string.IsNullOrEmpty(tmp = action ["enc"] + string.Empty)) { if (int.TryParse(tmp, out theEnc)) { encoding = Encoding.GetEncoding(theEnc); } else { encoding = Encoding.GetEncoding(tmp); } } } catch { } if (context != null) { context.Response.ContentEncoding = encoding; context.Response.ContentType = "text/csv; charset=" + encoding.WebName; context.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + SafeName(((exportList == null) ? context.Request.QueryString ["t"] : exportList.Title) + " " + JsonSchemaManager.GetDisplayName(action, "ExportActions", false)) + "_" + DateTime.Now.Ticks + ".csv" + "\""); } try { if ((action ["bom"] is bool) && (bool)action ["bom"]) { writer.Write("\uFEFF"); } } catch { } if (is2) { acsep = action ["sep"] + string.Empty; if (!string.IsNullOrEmpty(separator)) { sep = separator; } else if ((action ["excel"] is bool) && ((bool)action ["excel"]) && (string.IsNullOrEmpty(acsep) || acsep == "s")) { sep = ";"; } else if (acsep == "t") { sep = "\t"; } } if (!JsonSchemaManager.Bool(action ["nf"], false)) { for (int i = 0; i < listColumns.Length; i++) { fieldName = (((pos = listColumns [i].IndexOf(':')) <= 0) ? (listColumns [i]) : (listColumns [i].Substring(pos + 1))).Trim(); if ((fieldName == "ID") && (i == 0)) { fieldName = "\"ID\""; } writer.Write(fieldName + ((i == listColumns.Length - 1) ? ("\r\n") : (sep))); } } if (is2 && !string.IsNullOrEmpty(fs)) { filters = JSON.JsonDecode(fs) as ArrayList; } if (is2 && !string.IsNullOrEmpty(fj)) { fht = JSON.JsonDecode(fj) as Hashtable; } if ((filters != null) && (filters.Count == 0)) { filters = null; } if (exportList != null) { if ((listView == null) && (filters == null)) { listItems = exportList.Items; } else { query = ((listView != null) ? new SPQuery(listView) : new SPQuery()); if (listView == null) { query.Folder = exportList.RootFolder; viewXml = "<View><Query/></View>"; } else { viewXml = listView.SchemaXml; } query.AutoHyperlink = query.ExpandUserField = query.ItemIdQuery = false; query.ExpandRecurrence = query.IndividualProperties = query.IncludePermissions = query.IncludeMandatoryColumns = query.IncludeAttachmentVersion = query.IncludeAttachmentUrls = query.IncludeAllUserPermissions = query.RecurrenceOrderBy = true; query.RowLimit = 0; query.ViewFields = string.Empty; foreach (SPField f in ProductPage.TryEach <SPField> (exportList.Fields)) { query.ViewFields += string.Format(ProductPage.FORMAT_CAML_VIEWFIELD, f.InternalName); } if (filters != null) { doc.LoadXml(viewXml); if (!string.IsNullOrEmpty(viewXml = ProductPage.ApplyCore(exportList, viewXml, doc, filters, ref expGrps, false, fht, null))) { doc.LoadXml(viewXml); if ((node = doc.DocumentElement.SelectSingleNode("Query")) != null) { query.Query = node.InnerXml; } } } listItems = exportList.GetItems(query); } } csvWrite = delegate(string csvVal, string suffix) { writer.Write(CsvEscape(csvVal, sep, is2 && "1".Equals(unixFlag)) + suffix); }; if (isRoll) { ExportRollup(writer, action, rollOpt, exportWeb, fht, listColumns, locale, csvWrite, sep); } else if (listItems != null) { foreach (SPListItem item in ProductPage.TryEach <SPListItem> (listItems)) { for (int i = 0; i < listColumns.Length; i++) { skipRow = false; if ((!string.IsNullOrEmpty(versioning)) && (i == verIndex)) { versions = new List <SPListItemVersion> (); verVals = new Dictionary <string, string> (); colVal = string.Empty; foreach (SPListItemVersion v in item.Versions) { versions.Add(v); } versions.Sort(delegate(SPListItemVersion one, SPListItemVersion two) { return(one.VersionLabel.CompareTo(two.VersionLabel)); }); if (versionRows && (versions.Count > 1)) { skipRow = true; csvWrite(string.Empty, "\r\n"); for (int v = versions.Count - 1; v >= 0; v--) { for (int vc = 0; vc < listColumns.Length; vc++) { if (vc == verIndex) { csvWrite(versions [v].VersionLabel, ((vc == (listColumns.Length - 1)) ? "\r\n" : sep)); } else { colVal = string.Empty; if (!"ID".Equals(fieldName = ((pos = listColumns [vc].IndexOf(':')) <= 0) ? (listColumns [vc]) : (listColumns [vc].Substring(0, pos)))) { field = ProductPage.GetField(item, fieldName); val = string.Empty; try { val = versions [v] [fieldName]; } catch { } colVal = GetExportValue(exportWeb, val, field, locale, mulSep); } csvWrite(colVal, ((vc == (listColumns.Length - 1)) ? "\r\n" : sep)); } } } } else { for (int v = 0; v < versions.Count; v++) { subVersion = versions [v].VersionLabel + " " + versions [v].Created.ToLocalTime() + "\r\n" + versions [v].CreatedBy.LookupValue; for (int lc = 0; lc < listColumns.Length; lc++) { if (lc != verIndex) { try { colName = ((pos = listColumns [lc].IndexOf(':')) <= 0) ? (listColumns [lc]) : (listColumns [lc].Substring(0, pos).Trim()); if ((field = ProductPage.GetField(item, colName)) != null) { colName = field.InternalName; } try { val = versions [v] [colName]; } catch { val = null; } newVerVal = GetExportValue(exportWeb, val, field, locale, mulSep); if ((!verVals.TryGetValue(colName, out verVal)) || (verVal != newVerVal)) { verVals [colName] = newVerVal; subVersion += ("\r\n" + (((pos = listColumns [lc].IndexOf(':')) <= 0) ? (listColumns [lc]) : (listColumns [lc].Substring(pos + 1).Trim())) + ": " + newVerVal); } } catch { } } } colVal = subVersion + "\r\n\r\n" + colVal; } } } else { if ((field = ProductPage.GetField(item, (fieldName = ((pos = listColumns [i].IndexOf(':')) <= 0) ? (listColumns [i]) : (listColumns [i].Substring(0, pos))))) != null) { val = item [field.Id]; } else { try { val = item [fieldName]; } catch { val = null; } } colVal = GetExportValue(exportWeb, val, field, locale, mulSep); } if (!skipRow) { csvWrite(colVal, ((i == listColumns.Length - 1) ? "\r\n" : sep)); } } } } } }