-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.cs
3552 lines (3000 loc) · 128 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Windows.Forms;
using System.IO;
using BandR;
using BandR.CustObjs;
using Microsoft.SharePoint.Client;
using File = System.IO.File;
using Form = System.Windows.Forms.Form;
using System.Text.RegularExpressions;
namespace SPFileZilla2013
{
public partial class Form1 : Form
{
public string editorFontSize { get; set; }
public string editorColorIsWhite { get; set; }
public string editorTextIsWrap { get; set; }
public BackgroundWorker bgWorker = null;
public FormProfiles formProfiles = null;
public FormAbout formAbout = null;
public FormUpdateFields formUpdateFields = null;
public FormViewEditFile formViewEditFile = null;
public FormManagePropBag formManagePropBag = null;
public int GetRowLimit()
{
var rl = GenUtil.SafeToNum(System.Configuration.ConfigurationManager.AppSettings["rowLimit"]);
return rl > 0 ? rl : 100;
}
public class CurSPLocationObj
{
public string siteUrl;
public Guid? listId;
public string rootFolderUrl;
public string curFolderUrl;
public bool isRootFolder
{
get { return rootFolderUrl == curFolderUrl; }
}
}
public CurSPLocationObj curSPLocationObj = new CurSPLocationObj();
public string curLvSelected;
public SessionDetail sessionDetail = null;
/// <summary>
/// </summary>
public Form1()
{
InitializeComponent();
editorFontSize = "9";
editorColorIsWhite = "1";
editorTextIsWrap = "0";
toolStripStatusLabel1.Text = "";
this.Closed += new EventHandler(Form1_Closed);
tbCurFSUrl.MouseClick += new MouseEventHandler(tbCurFSUrl_MouseClick);
lvFS.MultiSelect = true;
lvSP.MultiSelect = true;
//lvFS.MouseClick += new MouseEventHandler(lvFS_MouseClick);
//lvSP.MouseClick += new MouseEventHandler(lvSP_MouseClick);
lvFS.MouseDown += new MouseEventHandler(lvFS_MouseDown);
lvSP.MouseDown += new MouseEventHandler(lvSP_MouseDown);
btnCopyToSP.Click += new EventHandler(btnCopyToSP_Click);
btnCopyToFileSys.Click += new EventHandler(btnCopyToFileSys_Click);
// tips
pbProfiles.MouseHover += pbProfiles_MouseHover;
pbProfiles.MouseLeave += pbProfiles_MouseLeave;
lvSP.MouseHover += new EventHandler(lvSP_MouseHover);
lvSP.MouseLeave += new EventHandler(lvSP_MouseLeave);
lvFS.MouseHover += lvFS_MouseHover;
lvFS.MouseLeave += lvFS_MouseLeave;
tbCurFSUrl.MouseHover += new EventHandler(tbCurFSUrl_MouseHover);
tbCurFSUrl.MouseLeave += new EventHandler(tbCurFSUrl_MouseLeave);
btnCopyToFileSys.MouseHover += new EventHandler(btnCopyToFileSys_MouseHover);
btnCopyToFileSys.MouseLeave += new EventHandler(btnCopyToFileSys_MouseLeave);
btnCopyToSP.MouseHover += new EventHandler(btnCopyToSP_MouseHover);
btnCopyToSP.MouseLeave += new EventHandler(btnCopyToSP_MouseLeave);
cbOverwrite.MouseHover += cbOverwrite_MouseHover;
cbOverwrite.MouseLeave += cbOverwrite_MouseLeave;
// right click menu
deleteToolStripMenuItem.Click += new EventHandler(deleteToolStripMenuItem_Click);
renameToolStripMenuItem.Click += new EventHandler(renameToolStripMenuItem_Click);
sendToDestinationToolStripMenuItem.Click += new EventHandler(sendToDestinationToolStripMenuItem_Click);
createFolderToolStripMenuItem.Click += new EventHandler(createFolderToolStripMenuItem_Click);
copyPathToClipboardToolStripMenuItem.Click += new EventHandler(copyPathToClipboardToolStripMenuItem_Click);
moveFilesToolStripMenuItem.Click += new System.EventHandler(moveFilesToolStripMenuItem_Click);
updateFieldsToolStripMenuItem.Click += new System.EventHandler(updateFieldsToolStripMenuItem_Click);
checkInMinorFilesToolStripMenuItem.Click += new System.EventHandler(checkInMinorFilesToolStripMenuItem_Click);
checkInMajorFilesToolStripMenuItem.Click += new System.EventHandler(checkInMajorFilesToolStripMenuItem_Click);
checkInOverwriteFilesToolStripMenuItem.Click += new System.EventHandler(checkInOverwriteFilesToolStripMenuItem_Click);
checkOutFilesToolStripMenuItem1.Click += new System.EventHandler(checkOutFilesToolStripMenuItem1_Click);
publishFilesToolStripMenuItem1.Click += new System.EventHandler(publishFilesToolStripMenuItem1_Click);
undoCheckOutFilesToolStripMenuItem.Click += new System.EventHandler(undoCheckOutFilesToolStripMenuItem_Click);
copyFilesToolStripMenuItem.Click += new EventHandler(copyFilesToolStripMenuItem_Click);
viewEditFileAsTextToolStripMenuItem.Click += viewEditFileAsTextToolStripMenuItem_Click;
btnQuickConnectSP.Click += new System.EventHandler(btnQuickConnectSP_Click);
pbProfiles.Click += new System.EventHandler(picbtnProfiles_Click);
profilesToolStripMenuItem.Click += new System.EventHandler(profilesToolStripMenuItem_Click);
exitToolStripMenuItem.Click += new System.EventHandler(exitToolStripMenuItem_Click);
aboutToolStripMenuItem.Click += new System.EventHandler(aboutToolStripMenuItem_Click);
pbLogo.Click += new EventHandler(picbtnLogo_Click);
pbFileZilla.Click += new EventHandler(picbtnFileZilla_Click);
lvSP.ColumnClick += new ColumnClickEventHandler(lvSP_ColumnClick);
lvFS.ColumnClick += new ColumnClickEventHandler(lvFS_ColumnClick);
lvFS.SelectedIndexChanged += new EventHandler(lvFS_SelectedIndexChanged);
lvSP.SelectedIndexChanged += new EventHandler(lvSP_SelectedIndexChanged);
// dragging
lvSP.AllowDrop = true;
lvSP.DragEnter += new DragEventHandler(lvSP_DragEnter);
lvSP.DragDrop += new DragEventHandler(lvSP_DragDrop);
tbCurFSUrl.Text = @"C:\";
GetRecentSessionInfo();
LoadFSListView_GetFoldersFiles(tbCurFSUrl.Text.Trim(), 0);
EnableFormFields();
// #testing
//tbQuickSPSiteUrl.Text = "http://sp.bandr.com/sites/zen20";
//tbQuickSPUsername.Text = "bsteinhauser";
//tbQuickSPPassword.Text = "abc123#";
//tbQuickSPDomain.Text = "versatrend";
}
// EVENT FUNCTIONS *********************************************************
#region "mouse tips"
/// <summary>
/// </summary>
public void cbOverwrite_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void cbOverwrite_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "When checked files will be overwritten.";
}
/// <summary>
/// </summary>
public void lvFS_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void lvFS_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Double click file to upload, right click menu too.";
}
/// <summary>
/// </summary>
public void pbProfiles_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void pbProfiles_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Click here to open your saved profiles, connect quickly to SharePoint sites.";
}
/// <summary>
/// </summary>
public void btnCopyToSP_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void btnCopyToSP_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Click here to copy files/folders to SharePoint.";
}
/// <summary>
/// </summary>
public void btnCopyToFileSys_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void btnCopyToFileSys_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Click here to copy files/folders to Windows.";
}
/// <summary>
/// </summary>
public void tbCurFSUrl_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void tbCurFSUrl_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Click here to open a dialog to choose a Windows folder.";
}
/// <summary>
/// </summary>
public void lvSP_MouseLeave(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "";
}
/// <summary>
/// </summary>
public void lvSP_MouseHover(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Drag/drop here, double click file to download, right click menu too.";
}
#endregion
//public void lvSP_MouseClick(object sender, MouseEventArgs e)
//{
// if (e.Button == MouseButtons.Right)
// {
// curLvSelected = "lvSP";
// }
//}
//public void lvFS_MouseClick(object sender, MouseEventArgs e)
//{
// if (e.Button == MouseButtons.Right)
// {
// curLvSelected = "lvFS";
// }
//}
/// <summary>
/// </summary>
public void lvSP_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
/// <summary>
/// </summary>
public void lvSP_DragDrop(object sender, DragEventArgs e)
{
if (curSPLocationObj.listId == null)
{
cout("Please open a SharePoint Library.");
return;
}
string[] paths = (string[])e.Data.GetData(DataFormats.FileDrop);
var selFSItems = new List<string>();
foreach (string path in paths)
{
try
{
var di = new DirectoryInfo(path);
if (di.Exists)
selFSItems.Add("0" + path);
}
catch {}
try
{
var fi = new FileInfo(path);
if (fi.Exists)
selFSItems.Add("1" + path);
}
catch { }
}
cout("Copying to SharePoint...");
DisableFormFields();
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork_CopyToSp);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted_CopyToSp);
bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_All_ProgressChanged);
bgWorker.WorkerReportsProgress = true;
bgWorker.RunWorkerAsync(new List<object>()
{
selFSItems
});
}
/// <summary>
/// </summary>
public void lvSP_SelectedIndexChanged(object sender, EventArgs e)
{
ChangeListViewBgColor(lvSP);
}
/// <summary>
/// </summary>
public void lvFS_SelectedIndexChanged(object sender, EventArgs e)
{
ChangeListViewBgColor(lvFS);
}
/// <summary>
/// </summary>
public void lvFS_ColumnClick(object sender, ColumnClickEventArgs e)
{
// 0=name, 1=size, 2=moddate
LoadFSListView_GetFoldersFiles(tbCurFSUrl.Text.Trim(), e.Column);
}
/// <summary>
/// </summary>
public void lvSP_ColumnClick(object sender, ColumnClickEventArgs e)
{
// 0=name, 1=size, 2=moddate
if (curSPLocationObj.listId != null)
{
if (curSPLocationObj.isRootFolder)
{
LoadSPListView_RootObjects(curSPLocationObj.listId.ToString(), e.Column);
}
else if (!curSPLocationObj.isRootFolder)
{
LoadSPListView_FolderObjects(curSPLocationObj.curFolderUrl, e.Column);
}
}
}
/// <summary>
/// </summary>
public void picbtnFileZilla_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://filezilla-project.org/");
}
/// <summary>
/// </summary>
public void picbtnLogo_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.bandrsolutions.com/?utm_source=SPFileZilla&utm_medium=application&utm_campaign=SPFileZilla");
}
/// <summary>
/// </summary>
public void Form1_Closed(object sender, EventArgs e)
{
SaveCurrentSessionInfo();
if (formProfiles != null)
{
formProfiles.Close();
}
if (formAbout != null)
{
formAbout.Close();
}
if (formUpdateFields != null)
{
formUpdateFields.Close();
}
if (formViewEditFile != null)
{
formViewEditFile.Close();
}
if (formManagePropBag != null)
{
formManagePropBag.Close();
}
}
/// <summary>
/// </summary>
public void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (formAbout != null)
{
formAbout.Close();
}
formAbout = new FormAbout();
formAbout.Show();
formAbout.Focus();
formAbout.StartPosition = FormStartPosition.Manual;
formAbout.Location = new Point(this.Location.X + 75, this.Location.Y + 75);
}
/// <summary>
/// </summary>
public void profilesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (formProfiles != null)
{
formProfiles.Close();
}
formProfiles = new FormProfiles();
formProfiles.Show();
formProfiles.Focus();
formProfiles.StartPosition = FormStartPosition.Manual;
formProfiles.Location = new Point(this.Location.X + 25, this.Location.Y + 25);
formProfiles.form1 = this;
}
/// <summary>
/// </summary>
public void picbtnProfiles_Click(object sender, EventArgs e)
{
if (formProfiles != null)
{
formProfiles.Close();
}
formProfiles = new FormProfiles();
formProfiles.Show();
formProfiles.Focus();
formProfiles.StartPosition = FormStartPosition.Manual;
formProfiles.Location = new Point(this.Location.X + 25, this.Location.Y + 25);
formProfiles.form1 = this;
}
/// <summary>
/// </summary>
public void bgWorker_All_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
var obj = e.UserState;
cout(obj.ToString());
}
#region "RIGHT CLICK MENU"
/// <summary>
/// </summary>
public void copyFilesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (GenUtil.IsEqual(curLvSelected, "lvSP"))
{
// get selected files
var selItems = GetListViewSelItemsText(lvSP);
if (!selItems.Any())
{
return;
}
var lstFilePaths = new List<string>();
var lstFolderPaths = new List<string>();
foreach (string selItem in selItems)
{
if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FILE.ToString())
{
lstFilePaths.Add(selItem.Substring(1));
}
else if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FOLDER.ToString())
{
lstFolderPaths.Add(selItem.Substring(1));
}
}
// get new path
string newPath = Microsoft.VisualBasic.Interaction.InputBox("Enter destination server relative path for file(s) (do not include filenames):", "Copy File(s)", "", -1, -1);
if (GenUtil.IsNull(newPath))
{
cout("Path cannot be blank.");
return;
}
DisableFormFields();
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork_CopyFiles);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted_CopyFiles);
bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_All_ProgressChanged);
bgWorker.WorkerReportsProgress = true;
bgWorker.RunWorkerAsync(new List<object>()
{
lstFilePaths,
lstFolderPaths,
newPath
});
}
}
/// <summary>
/// </summary>
public void bgWorker_DoWork_CopyFiles(object sender, DoWorkEventArgs e)
{
var lstArgs = e.Argument as List<object>;
var lstFilePaths = lstArgs[0] as List<string>;
var lstFolderPaths = lstArgs[1] as List<string>;
var destServRelFolderPath = lstArgs[2].ToString();
var refreshNeeded = false;
DoMoveOrCopyWork(true, false, lstFilePaths, lstFolderPaths, destServRelFolderPath, out refreshNeeded);
e.Result = new List<object>() { refreshNeeded };
}
/// <summary>
/// </summary>
private void DoMoveOrCopyWork(bool doCopy, bool doMove, List<string> lstFilePaths, List<string> lstFolderPaths, string destServRelFolderPath, out bool refreshNeeded)
{
var msg = "";
refreshNeeded = false;
var lstSubObjects = new List<SPTree_FolderFileObj>();
// add files to list
foreach (string filePath in lstFilePaths)
{
lstSubObjects.Add(new SPTree_FolderFileObj()
{
dtModified = null,
folderLevel = filePath.ToCharArray().Count(x => x == '/'),
treeNodeType = Enums.TreeNodeTypes.FILE,
name = filePath.Substring(filePath.LastIndexOf('/') + 0),
url = filePath,
length = 0
});
}
// for any folders selected, get all the files in those folders, add to list for processing
foreach (string curServRelFolderPath in lstFolderPaths)
{
bgWorker.ReportProgress(0, string.Format("cur folder path: " + curServRelFolderPath));
if (!SpComHelper.GetListAllFilesFolderLevel(
tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curServRelFolderPath, ref lstSubObjects, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error getting folder sub objects, {0}: {1}", curServRelFolderPath, msg));
}
}
// process all files
foreach (var curSubObject in lstSubObjects.OrderBy(x => x.folderLevel))
{
//bgWorker.ReportProgress(0, string.Format("Processing sub object: {0}", curSubObject.url));
var oldLocPath = curSubObject.url;
var newLocPath = GenUtil.EnsureStartsWithForwardSlash(destServRelFolderPath.CombineWeb(curSubObject.url.Replace(curSPLocationObj.curFolderUrl, "")));
//bgWorker.ReportProgress(0, string.Format(" -- new dest path: " + newLocPath));
var stackPathParts = new Stack<string>(newLocPath.Split("-".ToCharArray()));
var fileName = stackPathParts.Pop();
//tcout(" -- filename", fileName);
//tcout(" -- tmpPath", string.Join("/", stackPathParts.Reverse().ToArray()));
var stackBackTrack = new Stack<string>();
var foundFolderPath = "";
var exists = false;
while (true)
{
// quit when folder found, or exception
// check curFolderPath exists
var curDestFolderPath = string.Join("/", stackPathParts.Reverse().ToArray());
//tcout(" -- cur path to check", curDestFolderPath);
if (!SpComHelper.CheckFolderExists(
tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, curDestFolderPath, out exists, out msg))
{
// error
tcout("ERROR: " + msg);
break;
}
else if (exists)
{
// path found, quit
foundFolderPath = curDestFolderPath;
break;
}
else
{
// path not found, pop folder name off end of string, save in stack, continue
stackBackTrack.Push(stackPathParts.Pop());
}
if (!stackPathParts.Any())
{
break;
}
}
if (!foundFolderPath.IsNull())
{
// ok to copy
if (stackBackTrack.Any())
{
//tcout("back track path", string.Join("/", stackBackTrack.ToArray()));
// create these folders
while (true)
{
var folderName = stackBackTrack.Pop();
if (!SpComHelper.CreateFolderInSharePoint(tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, folderName, foundFolderPath, out msg))
{
tcout("ERROR: " + msg);
break;
}
foundFolderPath = foundFolderPath.CombineWeb(folderName);
tcout("New folder created", foundFolderPath);
if (!stackBackTrack.Any())
{
break;
}
}
}
if (doCopy)
{
if (!SpComHelper.CopySPFile(
tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, oldLocPath, newLocPath, cbOverwrite.Checked, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error copying file, {0}: {1}", oldLocPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Copied Successfully: {0}", newLocPath));
}
}
else if (doMove)
{
if (!SpComHelper.MoveSPFile(
tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, oldLocPath, newLocPath, cbOverwrite.Checked, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error moving file, {0}: {1}", oldLocPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Moved Successfully: {0}", newLocPath));
refreshNeeded = true;
}
}
}
}
}
/// <summary>
/// </summary>
public void bgWorker_RunWorkerCompleted_CopyFiles(object sender, RunWorkerCompletedEventArgs e)
{
EnableFormFields();
}
/// <summary>
/// </summary>
private void DoCheckInCheckOutPublishWork(string action, List<string> lstFilePaths, List<string> lstFolderPaths, string comment)
{
var msg = "";
var lstSubObjects = new List<SPTree_FolderFileObj>();
// add files to list
foreach (string filePath in lstFilePaths)
{
lstSubObjects.Add(new SPTree_FolderFileObj()
{
dtModified = null,
folderLevel = filePath.ToCharArray().Count(x => x == '/'),
treeNodeType = Enums.TreeNodeTypes.FILE,
name = filePath.Substring(filePath.LastIndexOf('/') + 0),
url = filePath,
length = 0
});
}
// for any folders selected, get all the files in those folders, add to list for processing
foreach (string curServRelFolderPath in lstFolderPaths)
{
bgWorker.ReportProgress(0, string.Format("cur folder path: " + curServRelFolderPath));
if (!SpComHelper.GetListAllFilesFolderLevel(
tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curServRelFolderPath, ref lstSubObjects, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error getting folder sub objects, {0}: {1}", curServRelFolderPath, msg));
}
}
// process all files
foreach (var curSubObject in lstSubObjects.OrderBy(x => x.folderLevel))
{
var curPath = curSubObject.url;
if (action.IsEqual("CHECKINMINOR"))
{
if (!SpComHelper.CheckInSPFile(
tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(), tbQuickSPDomain.Text.Trim(),
cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curPath, comment, CheckinType.MinorCheckIn, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error @ MinorCheckIn File, {0}: {1}", curPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Minor Check-In Successful: {0}", curPath));
}
}
else if (action.IsEqual("UNDOCHECKOUT"))
{
if (!SpComHelper.UndoCheckOutSPFile(tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(),
tbQuickSPDomain.Text.Trim(), cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curPath, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error @ UndoCheckOut File, {0}: {1}", curPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File UndoCheck-Out Successful: {0}", curPath));
}
}
else if (action.IsEqual("PUBLISHFILE"))
{
if (!SpComHelper.PublishSPFile(tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(),
tbQuickSPDomain.Text.Trim(), cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curPath, comment, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error @ Publish File, {0}: {1}", curPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Published Successfully: {0}", curPath));
}
}
else if (action.IsEqual("CHECKINMAJOR"))
{
if (!SpComHelper.CheckInSPFile(tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(),
tbQuickSPDomain.Text.Trim(), cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curPath, comment, CheckinType.MajorCheckIn, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error @ MajorCheckIn File, {0}: {1}", curPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Major Check-In Successful: {0}", curPath));
}
}
else if (action.IsEqual("CHECKINOVERWRITE"))
{
if (!SpComHelper.CheckInSPFile(tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(),
tbQuickSPDomain.Text.Trim(), cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curPath, comment, CheckinType.OverwriteCheckIn, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error @ OverwriteCheckIn File, {0}: {1}", curPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Overwrite Check-In Successful: {0}", curPath));
}
}
else if (action.IsEqual("CHECKOUT"))
{
if (!SpComHelper.CheckOutSPFile(tbQuickSPSiteUrl.Text.Trim(), tbQuickSPUsername.Text.Trim(), tbQuickSPPassword.Text.Trim(),
tbQuickSPDomain.Text.Trim(), cbIsSharePointOnline.Checked, curSPLocationObj.listId.Value, curPath, out msg))
{
bgWorker.ReportProgress(0, string.Format("Error @ CheckOut File, {0}: {1}", curPath, msg));
}
else
{
bgWorker.ReportProgress(0, string.Format("File Check-Out Successful: {0}", curPath));
}
}
}
}
/// <summary>
/// </summary>
public void undoCheckOutFilesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (GenUtil.IsEqual(curLvSelected, "lvSP"))
{
// get selected files
var selItems = GetListViewSelItemsText(lvSP);
if (!selItems.Any())
{
return;
}
var lstFilePaths = new List<string>();
var lstFolderPaths = new List<string>();
foreach (string selItem in selItems)
{
if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FILE.ToString())
{
lstFilePaths.Add(selItem.Substring(1));
}
else if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FOLDER.ToString())
{
lstFolderPaths.Add(selItem.Substring(1));
}
}
DisableFormFields();
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork_UndoCheckout);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted_UndoCheckout);
bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_All_ProgressChanged);
bgWorker.WorkerReportsProgress = true;
bgWorker.RunWorkerAsync(new List<object>()
{
lstFilePaths,
lstFolderPaths
});
}
}
/// <summary>
/// </summary>
public void bgWorker_DoWork_UndoCheckout(object sender, DoWorkEventArgs e)
{
var lstArgs = e.Argument as List<object>;
var lstFilePaths = lstArgs[0] as List<string>;
var lstFolderPaths = lstArgs[1] as List<string>;
DoCheckInCheckOutPublishWork("UNDOCHECKOUT", lstFilePaths, lstFolderPaths, "");
}
/// <summary>
/// </summary>
public void bgWorker_RunWorkerCompleted_UndoCheckout(object sender, RunWorkerCompletedEventArgs e)
{
EnableFormFields();
}
/// <summary>
/// </summary>
public void publishFilesToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (GenUtil.IsEqual(curLvSelected, "lvSP"))
{
// get selected files
var selItems = GetListViewSelItemsText(lvSP);
if (!selItems.Any())
{
return;
}
var lstFilePaths = new List<string>();
var lstFolderPaths = new List<string>();
foreach (string selItem in selItems)
{
if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FILE.ToString())
{
lstFilePaths.Add(selItem.Substring(1));
}
else if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FOLDER.ToString())
{
lstFolderPaths.Add(selItem.Substring(1));
}
}
// get new path
string comment = Microsoft.VisualBasic.Interaction.InputBox("Enter a comment:", "Approve File(s)", "", -1, -1);
DisableFormFields();
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork_PublishFiles);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted_PublishFiles);
bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_All_ProgressChanged);
bgWorker.WorkerReportsProgress = true;
bgWorker.RunWorkerAsync(new List<object>()
{
lstFilePaths,
lstFolderPaths,
comment
});
}
}
/// <summary>
/// </summary>
public void bgWorker_DoWork_PublishFiles(object sender, DoWorkEventArgs e)
{
var lstArgs = e.Argument as List<object>;
var lstFilePaths = lstArgs[0] as List<string>;
var lstFolderPaths = lstArgs[1] as List<string>;
var comment = lstArgs[2].ToString();
DoCheckInCheckOutPublishWork("PUBLISHFILE", lstFilePaths, lstFolderPaths, comment);
}
/// <summary>
/// </summary>
public void bgWorker_RunWorkerCompleted_PublishFiles(object sender, RunWorkerCompletedEventArgs e)
{
EnableFormFields();
}
/// <summary>
/// </summary>
public void checkInMinorFilesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (GenUtil.IsEqual(curLvSelected, "lvSP"))
{
// get selected files
var selItems = GetListViewSelItemsText(lvSP);
if (!selItems.Any())
{
return;
}
var lstFilePaths = new List<string>();
var lstFolderPaths = new List<string>();
foreach (string selItem in selItems)
{
if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FILE.ToString())
{
lstFilePaths.Add(selItem.Substring(1));
}
else if (selItem.Substring(0, 1) == Enums.TreeNodeTypes.FOLDER.ToString())
{
lstFolderPaths.Add(selItem.Substring(1));
}
}
// get new path
string comment = Microsoft.VisualBasic.Interaction.InputBox("Enter a comment:", "Check-In File(s)", "", -1, -1);
DisableFormFields();
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork_CheckInMinorFiles);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted_CheckInMinorFiles);
bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_All_ProgressChanged);
bgWorker.WorkerReportsProgress = true;
bgWorker.RunWorkerAsync(new List<object>()
{
lstFilePaths,
lstFolderPaths,
comment