Всем привет. Проблема такая> Не знаю как передать данные с одной формы на другую.
Я создал форму в Form1.cs Design. В этой форме имеются два Listbox. В Ribbon.cs(Word панель) у меня кнопка. Когда она нажимается то происходит>
C# |
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
| private void UuendaNimekiri_Click(object sender, RibbonControlEventArgs e)
{
Form1 MallideVorm = new Form1(); //Creating form from Form1
MallideVorm.Show(); // Showing form
int ConnectionTest = 0; //will try to connect once
ClientContext ctx = new ClientContext("https://Some.some/some");
//Configure the handler that will add the header.
ctx.ExecutingWebRequest +=
new EventHandler<WebRequestEventArgs>(ctx_MixedAuthRequest);
//Set the Windows credentials.
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Get the web.
Web w = ctx.Web;
//Load lists with all properties.
List list = ctx.Web.Lists.GetByTitle("Dokumendid");
try
{
ctx.ExecuteQuery();
}
catch
{ ConnectionTest = 1; }
if (ConnectionTest == 0)
{
ctx.Load(list);
ctx.Load(list.RootFolder);
ctx.Load(list.RootFolder.Folders);
ctx.Load(list.RootFolder.Files);
ctx.ExecuteQuery();
FolderCollection fcol = list.RootFolder.Folders;
List<string> lstFile = new List<string>();
foreach (Folder f in fcol)
{
if (f.Name == "Test")
{
ctx.Load(f.Folders);
ctx.Load(f.Files);
ctx.ExecuteQuery();
FolderCollection folderCol = f.Folders;
FileCollection fileCol = f.Files;
string str = "";
foreach (Microsoft.SharePoint.Client.Folder folder in folderCol)
{
str = folder.Name;
// File.AppendAllText(@"C:\install\CSharp\tulemus.txt", $"File name is: {str}" + Environment.NewLine); //for testings
foreach (Form1 frm in System.Windows.Forms.Application.OpenForms)
{
if (frm.GetType() == typeof(Form1))
{
//RibbonDropDownItem ddItem1 = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
//ddItem1.Label = $"{str}";
Form1 frmTemp = (Form1)frm;
//ddList.Items.Add(ddItem1);
MallideVorm.addItemToListBoxFolder(str);
}
}
}
foreach (Microsoft.SharePoint.Client.File file in fileCol)
{
str = file.Name;
// File.AppendAllText(@"C:\install\CSharp\tulemus.txt", $"File name is: {str}" + Environment.NewLine); //for testings
foreach (Form1 frm in System.Windows.Forms.Application.OpenForms)
{
if (frm.GetType() == typeof(Form1))
{
//RibbonDropDownItem ddItem1 = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
//ddItem1.Label = $"{str}";
Form1 frmTemp = (Form1)frm;
//ddList.Items.Add(ddItem1);
MallideVorm.addItemToListBoxFiles(file.Name);
}
}
}
}
}
}else { Interaction.MsgBox(" Ei saa ühendust lehega https://kontor.rik.ee/prok/ \n Kas oled võrgus? Proovi kas saad Chrome-is lehele ligi.",MsgBoxStyle.Critical); }
} |
|
Создается новая форма и в ListBoxы записываются данные.
Затем я хочу использовать эти данные в Form1.cs. Там код такой>
C# |
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
| private void FormFilesBox_SelectedIndexChanged(object sender, EventArgs e)
{
//_______________________________________________________Sharepoindist faili alla laadimine ja sealt avamine________________________________________
string selectedFile = FormFilesBox.SelectedItem.ToString();
File.AppendAllText(@"C:\install\CSharp\tulemus.txt", $"File name is: {selectedFile}" + Environment.NewLine);
var destinationFolder = @"C:\install\CSharp\TestkaustDoc";
ClientContext ctx = new ClientContext("https://Some.some/some");
//Configure the handler that will add the header.
ctx.ExecutingWebRequest +=
new EventHandler<WebRequestEventArgs>(ctx_MixedAuthRequest);
//Set the Windows credentials.
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Get a reference to the SharePoint site
var web = ctx.Web;
// Get a reference to the document library
var list = ctx.Web.Lists.GetByTitle("Dokumendid");
// Get the list of files you want to export. I'm using a query
// to find all files where the "Status" column is marked as "Approved"
var camlQuery = new CamlQuery
{
ViewXml = @"<View>
<Query>
<Where>
<Eq>
<FieldRef Name=""FileLeafRef"" />
<Value Type=""Text"">" + $"{selectedFile}" + @"</Value>
</Eq>
</Where>
</Query>
</View>"
};
camlQuery.FolderServerRelativeUrl = "/prok/Shared Documents/Test";
// Retrieve the items matching the query
var items = list.GetItems(camlQuery);
// Make sure to load the File in the context otherwise you won't go far
ctx.Load(items, items2 => items2.IncludeWithDefaultProperties
(item => item.DisplayName, item => item.File));
// Execute the query and actually populate the results
ctx.ExecuteQuery();
// Iterate through every file returned and save them
foreach (var item in items)
{
using (FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, item.File.ServerRelativeUrl))
{
// Combine destination folder with filename -- don't concatenate
// it's just wrong!
var filePath = Path.Combine(destinationFolder, item.File.Name);
// Erase existing files, cause that's how I roll
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
// Create the file
using (var fileStream = System.IO.File.Create(filePath))
{
fileInfo.Stream.CopyTo(fileStream);
}
}
} |
|
В начале как я понимаю мне нужно перенять данные которые выбраны и передать их в форму которую я использую.
Как это сделать?