/// <summary> /// </summary> private void Form1_Load(object sender, EventArgs e) { picLogoWait.Visible = false; picLogoWait.Refresh(); UseRecentSessionInfo(); { // init ddls ddlCamlExamples.Items.Clear(); foreach (object key in CamlExamples.GetCamlExamples(formChooser.appMode != Chooser.AppMode.UseSOM).Keys) { ddlCamlExamples.Items.Add(key.ToString()); } } { // init textboxes lblListName.Text = ""; toolStripStatusLabel1.Text = ""; txtSiteUrl.Text = GenUtil.IsNull(txtSiteUrl.Text) ? "http://localhost" : txtSiteUrl.Text; txtQuery.Text = GenUtil.IsNull(txtQuery.Text) ? CamlExamples.GetCamlExamples(formChooser.appMode != Chooser.AppMode.UseSOM)["Replace with: Simple Where 4"].ToString() : txtQuery.Text; txtViewFields.Text = GenUtil.IsNull(txtViewFields.Text) ? @"<FieldRef Name=""Title"" />" : txtViewFields.Text; txtViewAttributes.Text = GenUtil.IsNull(txtViewAttributes.Text) ? "Scope=\"Recursive\"" : txtViewAttributes.Text; } { // init mouse hover tips tvLists.MouseHover += new EventHandler(tvLists_MouseHover); tvFields.MouseHover += new EventHandler(tvFields_MouseHover); btnExportCode.MouseHover += new EventHandler(btnExportXML_MouseHover); txtSiteUrl.MouseHover += new EventHandler(txtSiteUrl_MouseHover); txtQuery.MouseHover += new EventHandler(txtQuery_MouseHover); gvFields.MouseHover += new EventHandler(gvFields_MouseHover); } { lnkToggleFieldsName.Text = text_show_internalnames; tvLists.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(tvLists_NodeMouseDoubleClick); tvFields.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(tvFields_NodeMouseDoubleClick); } { txtSiteUrl.KeyPress += new KeyPressEventHandler(txtSiteUrl_KeyPress); } { // init drag drop events tvFields.ItemDrag += new ItemDragEventHandler(tvFields_ItemDrag); txtViewFields.AllowDrop = true; txtViewFields.DragEnter += new DragEventHandler(txtViewFields_DragEnter); txtViewFields.DragDrop += new DragEventHandler(txtViewFields_DragDrop); txtQuery.AllowDrop = true; txtQuery.DragEnter += new DragEventHandler(txtQuery_DragEnter); txtQuery.DragDrop += new DragEventHandler(txtQuery_DragDrop); } { gvFields.CellDoubleClick += new DataGridViewCellEventHandler(gvFields_CellDoubleClick); } { picLogoNormal.Click += new EventHandler(pictureBox1_Click); } btnOpenListDetails.Visible = false; }
/// <summary> /// </summary> public static string RemoveWhiteSpace(object s) { return(Regex.Replace(GenUtil.SafeTrim(s), "[\\t\\r\\n]", "")); }
/// <summary> /// </summary> private void ExportGrid(DataGridView gv, string type) { var saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); saveFileDialog1.Filter = "Csv file (*.csv)|*.csv|All Files (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.AddExtension = true; saveFileDialog1.FileName = "export.csv"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { toolStripStatusLabel1.Text = "Running..."; statusStrip1.Refresh(); picLogoWait.Visible = true; picLogoWait.Refresh(); System.IO.StreamWriter streamWriter = null; try { streamWriter = new System.IO.StreamWriter(saveFileDialog1.FileName); string strHeader = ""; for (int i = 0; i < gv.Columns.Count; i++) { string curval = GenUtil.SafeTrim(gv.Columns[i].HeaderText); if (curval.Contains(",") && !curval.StartsWith("\"")) { strHeader += "\"" + curval + "\"" + ","; } else { strHeader += curval + ","; } } streamWriter.WriteLine(strHeader); for (int m = 0; m < gv.Rows.Count; m++) { string strRowValue = ""; for (int n = 0; n < gv.Columns.Count; n++) { string curval = GenUtil.SafeTrim(gv.Rows[m].Cells[n].Value); if (curval.Contains(",") && !curval.StartsWith("\"")) { strRowValue += "\"" + curval.Replace("\"", "'") + "\"" + ","; } else { strRowValue += curval.Replace("\"", "'") + ","; } } streamWriter.WriteLine(strRowValue); } } catch (Exception ex) { MessageBox.Show("ERROR: see status window below for details.", "ERROR"); GenUtil.LogIt(txtStatus, string.Format("ERROR: cannot export to CSV: {0}", ex.ToString())); } finally { if (streamWriter != null) { streamWriter.Close(); } } toolStripStatusLabel1.Text = oldStatusText; statusStrip1.Refresh(); picLogoWait.Visible = false; picLogoWait.Refresh(); } }