Greetings,
What control in Visual C# 2008 would allow me to set a path and get the value of that path.
For example:
I want the user to click a button then select a path where he/she would do the operation such as save a file in selected path.
You want to use a FolderBrowserDiaglog
var folderBrowserDiaglog = new FolderBrowserDiaglog();
if ( folderBrowserDiaglog.ShowDialog() == DialogResult.OK )
{
string path = folderBrowserDiaglog.SelectedPath;
}
I don't mean to repeat, but none of the other answers seemed to be exactly what you wanted.
There are 3 controls: FolderBrowserDialog, OpenFileDialog, and SaveFileDialog. There names are pretty intuitive. You use all 3 the same way. Tanascius has a good example in his post. The folder dialog you would use if you want the user to select a whole folder to look at. The open you would use if you want the user to select one or many files to open. Save is the same as open, but you would use it when saving a file out.
Hope this helps.
The FolderBrowse Dialog....
SaveFileDialog (for a file) or FolderBrowserDialog (for a folder). Located in the dialogs tab in the toolbox.
Assuming Windows Forms, try the OpenFileDialog. All common dialogs descend from CommonDialog, so looking at the descendents of that class may help, too.
Related
In C#-WinForms I use a OpenFileDialog. I want to get all files/filenames in a selected folder, without pressing the ok button of the OpenFileDialog.
Is there a good way to achieve this?
if i understood your question in the right way, you want to get the Filenames out of your selected folder. To archive that, you could use a FolderBrowserDialog.
FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
if(folderBrowser.ShowDialog() == DialogResult.OK)
{
var path = folderBrowser.SelectedPath;
System.Windows.IO.DirectoryInfo info = new System.Windows.IO.DirectoryInfo(path);
foreach(var file in info.GetFiles())
{
//do what you want with your files.
//example
listbox1.Items.Add(file.Name);
}
}
If you got some further question, feel free to ask.
-- EDIT --
Ok now i understood what you mean.
You want to get the files out of a folder when clicking on it.
Maybe build your own dialog (simple new window). With a treeview on it. And if you click on a treeviewitem, on ther other side it displays you the files and subfolder.
I've got a folderbrowserdialog that will open to a certain folder, lets say C:\Temp.
Within this folder are a number of folders, e.g C:\Temp\1\ C:\Temp\2\ etc.
Now i only want the user to be able to select a folder inside C:\Temp, e.g select 1 or 2.
Is there an easy way to do this within the folderbrowserdialog or shall i rethink my approach and just display the folders in a dropbox or something and have them select if from there?
Cheers
If it's not a SpecialFolder you can't limit it to this folder only. If it is a special folder, then you can set a RootFolder property for FolderBrowserDialog.
var d= new System.Windows.Forms.FolderBrowserDialog { RootFolder= Environment.SpecialFolder.LocalApplicationData};
d.ShowDialog();
I have a C# project. I choose the .ico file for it in property so it automatically added the .ico into the list from the "solution explorer".
I am using a "notifyIcon", and want to change the icon programmatically.
example a notifyIcon red when program is busy and green when free.
So i know i have to add a new embed resource for the second ico. but how to access to the already existing one that is the application ico?
i would like "something like"
notifyIcon1.Icon = AppName.greenico.ico; //default app ico
notifyIcon1.Icon = AppName.redico.ico; //ico ill add as embed resource i guess
is that possible? i saw some strange ExtractIco thingy... But i am sure its possible to reference straight to something already embed ain't it?
Found a really really easy solution.
First: Change "Build" properties of the two icons in "Solution Explorer" to "Embedded Ressource".
now in your code just set the two icons as variables:
public Icon greenIco = new Icon(typeof(MainFormName), "GreenIco.ico");
public Icon redIco = new Icon(typeof(MainFormName), "RedIco.ico");
then to use them, easy so:
notifyIcon1.Icon = greenIco;
as simple as that.
Hope it'll help someone else a day.
I have just purchased: http://www.add-in-express.com/outlook-regions/
The reason why I have purchased that product is because I need to show a custom form on the main view of outlook when a specific folder is selected. I have managed to do so by doing the following:
Create a new Project int visual studio of type (Outlook 2010 Add-in)
Once that project is created I add:
Because I want that form to show on the main folder view of mail (replace all other views) I select this option:
I click next and follow all the defaults in order to create the form.
Once that form is created I add the buttons and images I need. In this example I will just add a button.
when I then run outlook and select my inbox folder this is what shows up:
(In other words every time I select a folder of type olMailItem that form shows up)
So now I solve my goal to display my custom form on the "main view of outlook"
Now my question is how can I show that form only on specific folders. For example I do not want to show that form when the folder "Inbox" is selected but I do want to show it when the folder "Outbox" is selected for example
Let's try to hide the form and show the default view when the button is clicked.
In order to solve that problem I have looked at: http://www.add-in-express.com/forum/read.php?FID=5&TID=4540
I have done the same steps but the form shows up again! In other words the code behind of the button looks like:
private void button1_Click(object sender, EventArgs e)
{
// get current folder in this case its inbox the one that is selected
MAPIFolder currentFolder = Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder;
Globals.ThisAddIn.ADXOlForm1Item.FolderName = string.Empty;
// clear web properties DO NOT SHOW WEB VIEW
currentFolder.WebViewURL = string.Empty;
currentFolder.WebViewOn = false;
// RESET FOLDER BY SELECTING A DIFFERENT ONE THEN THE SAME ONE
NameSpace nameSpace = Globals.ThisAddIn.Application.GetNamespace("MAPI");
MAPIFolder outboxFolder = nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderOutbox);
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = outboxFolder; // CHANGE FOLDER TO A DIFFERNT ONE
System.Windows.Forms.Application.DoEvents();
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = currentFolder; // SET INBOX AGAIN
}
when I run that code the default view shows up for 1 second then it get's replaced with the form!
-------------------------------------------Edit-------------------------------------------
When I add the form region Addin Express adds a ADXOlFormsManager and a ADXOlFormsCollectionItem for the form that I created. Based on your answer I have done:
#region ADXOlForm1
// TODO: Use the ADXOlForm1Item properties to configure the region's location, appearance and behavior.
// See the "The UI Mechanics" chapter of the Add-in Express Developer's Guide for more information.
ADXOlForm1Item = new ADXOlFormsCollectionItem();
ADXOlForm1Item.FolderName = "MyCustomFolder"; // <---- ADDED THIS LINE HOPING TO SHOW THIS FORM ONLY WHEN THAT FOLDER IS SELECTED
ADXOlForm1Item.ExplorerLayout = ADXOlExplorerLayout.WebViewPane;
ADXOlForm1Item.ExplorerItemTypes = ADXOlExplorerItemTypes.olMailItem;
ADXOlForm1Item.UseOfficeThemeForBackground = true;
ADXOlForm1Item.FormClassName = typeof(ADXOlForm1).FullName;
this.FormsManager.Items.Add(ADXOlForm1Item);
#endregion
I was hoping for that form to only show up in MyCustomFolder but it does shows up when selecting any folder of type ADXOlExplorerItemTypes.olMailItem. Perhaps I am doing something wrong....
In other words I was hoping for only the MAPIFolder MyCustomFolder folder had the properties
WebViewOn=true;
WebViewURL = "...AppData\Local\Temp\AddinExpress\ADXOlFormGeneral.html"
but as I traverse all the folders in outlook I can see that all of them have those properties even after specifying ADXOlForm1Item.FolderName = "MyCustomFolder";
Thank you for choosing Add-in Express Regions.
I understand the "main view of outlook" as the folder that Outlook shows when it is started. By default, that folder is the top-level folder of the message store. Note that this can be changed, see File | Options | Advanced | Start Outlook in this folder. I use this setting so that my Outlook shows me the Inbox at start-up.
The below is a citation from the section Context-Sensitivity of Your Outlook Form, see see the PDF file in the folder {Add-in Express}\Docs\ on your development PC:
ADXOlFormsCollectionItem provides a number of properties that allow specifying the context settings for your form. Say, you can specify item types for which your form will be shown. Note that in case of explorer, the item types that you specify are compared with the default item type of the current folder. In addition, you can specify the names of the folders for which your form will be shown in the FolderName and FolderNames properties; these properties also work for Inspector windows – in this case, the parent folder of the Outlook item is checked. An example of the folder path is "\Personal Folders\Inbox".
A special value in FolderName is an asterisk ('*'), which means "all folders". You can also specify message class(es) for which your form will be shown. Note that all context-sensitivity properties of an ADXOlFormsCollectionItem are processed using the OR Boolean operation. That is, specifying e.g. folder names extends, but not limits, the list of contexts for which your form will be shown.
That is, if you need to show the form for a given folder, specify the path to that folder in the FolderName/*FolderNames* property.
Regards from Belarus (GMT+3),
Andrei Smolin, Add-in Express Team Leader
May be this question is asked in past but I have searched and not found its solution yet.
I have tried all the options that I have found till now but all in vain.
SendKeys doesn't work as it does not fill the file input box with file path, that is to be uploaded.
Cannot set file input box "SetAttribute" value as there is no value attribute available:
thats all.
If I use element.focus() it pops up "choose file to upload" dialog and now I don't know how to fill it programmatically and open it in file input box.
I want it to be automated completed so that user does not have to interact with the application.
Application shall pick the file from hard disk from given file path and fill other fields of form then start uploading, all using webbrowser control in windows form application.
No solutions found!
Can anyone help please? (This is my first ever question on stackoverflow, therefore if I am doing anything wrong then please guide, I mean if I am not allowed to post such question!)
Here is the code:
HtmlElementCollection heCollection = doc.GetElementsByTagName("input");
foreach (HtmlElement heSpan in heCollection)
{
string strType = heSpan.GetAttribute("type");
string strName = heSpan.GetAttribute("name");
if (strType.Equals("file") && strName.Equals("file"))
{
heSpan.Focus();
//heSpan.SetAttribute("value", "test.jpg");
SendKeys.Send("C:\\1.txt");
//heSpan.InnerText = "c:\\1.txt";
}
//Title for the attachment
if (strName.Equals("field_title"))
{
heSpan.InnerText = "1.txt";
}
}
When this code executes, cursor starts blinking in fine input box (as I have set heSpan.focus()) but the file path doesn't show in the file input box.
If I implement
heSpan.InvokeMember("click");
It opens the choose a file to upload dialoge/popup window and there I get stuck, because I don't know how to fill that popup dynamically and then insert the file path in file input box.
Try setting the focus to the WebBrowser control right before you set the focus to the input field.
That worked for me.