FileDialogCustomPlacesCollection.Add Method

Definition

Adds a custom place to the FileDialogCustomPlacesCollection collection.

Overloads

Add(Guid)

Adds a custom place to the FileDialogCustomPlacesCollection collection.

Add(String)

Adds a custom place to the FileDialogCustomPlacesCollection collection.

Add(Guid)

Source:
FileDialogCustomPlacesCollection.cs
Source:
FileDialogCustomPlacesCollection.cs
Source:
FileDialogCustomPlacesCollection.cs

Adds a custom place to the FileDialogCustomPlacesCollection collection.

C#
public void Add(Guid knownFolderGuid);

Parameters

knownFolderGuid
Guid

A Guid that represents a Windows Vista Known Folder.

Examples

The following code example demonstrates how to use the Add method. To run this example, paste the following code into a Windows Form and call InitializeDialogAndButton from the form's constructor or Load event-handling method.

C#
private OpenFileDialog openFileDialog1;
private Button button1;

private void InitializeDialogAndButton()
{
    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
    this.button1 = new System.Windows.Forms.Button();
    this.button1.Location = new System.Drawing.Point(53, 37);
    this.button1.AutoSize = true;
    this.button1.Text = "Show dialog with custom places.";
    this.button1.UseVisualStyleBackColor = true;
    this.button1.Click += new System.EventHandler(this.button1_Click);
    this.Controls.Add(this.button1);
}

private void button1_Click(object sender, EventArgs e)
{
    // Add Pictures custom place using GUID.
    openFileDialog1.CustomPlaces.Add("33E28130-4E1E-4676-835A-98395C3BC3BB");

    // Add Links custom place using GUID
    openFileDialog1.CustomPlaces.Add(
        new FileDialogCustomPlace(
        new Guid("BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968")));

    // Add Windows custom place using file path.
    openFileDialog1.CustomPlaces.Add(@"c:\Windows");

    openFileDialog1.ShowDialog();
}

Remarks

The folder is added to custom places only for a particular FileDialog and is not a system or application wide change.

The folders are positioned in the custom places in the order that they are added to the FileDialog. The last one added will be at the top. If you add a custom place to the collection that does not exist on the computer running the application, the custom place will not be shown. GUIDs are case-insensitive. For a list of the available Windows Vista Known Folders, see Known Folder GUIDs for File Dialog Custom Places or the KnownFolders.h file in the Windows SDK.

See also

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Add(String)

Source:
FileDialogCustomPlacesCollection.cs
Source:
FileDialogCustomPlacesCollection.cs
Source:
FileDialogCustomPlacesCollection.cs

Adds a custom place to the FileDialogCustomPlacesCollection collection.

C#
public void Add(string path);
C#
public void Add(string? path);

Parameters

path
String

A folder path to the custom place.

Examples

The following code example demonstrates how to use the Add method. To run this example, paste the following code into a Windows Form and call InitializeDialogAndButton from the form's constructor or Load event-handling method.

C#
private OpenFileDialog openFileDialog1;
private Button button1;

private void InitializeDialogAndButton()
{
    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
    this.button1 = new System.Windows.Forms.Button();
    this.button1.Location = new System.Drawing.Point(53, 37);
    this.button1.AutoSize = true;
    this.button1.Text = "Show dialog with custom places.";
    this.button1.UseVisualStyleBackColor = true;
    this.button1.Click += new System.EventHandler(this.button1_Click);
    this.Controls.Add(this.button1);
}

private void button1_Click(object sender, EventArgs e)
{
    // Add Pictures custom place using GUID.
    openFileDialog1.CustomPlaces.Add("33E28130-4E1E-4676-835A-98395C3BC3BB");

    // Add Links custom place using GUID
    openFileDialog1.CustomPlaces.Add(
        new FileDialogCustomPlace(
        new Guid("BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968")));

    // Add Windows custom place using file path.
    openFileDialog1.CustomPlaces.Add(@"c:\Windows");

    openFileDialog1.ShowDialog();
}

Remarks

The folder is added to custom places only for a particular FileDialog and is not a system or application wide change.

The folders are positioned in the custom places in the order that they are added to the FileDialog. The last one added will be at the top.

See also

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10