PDA

View Full Version : مبتدی: OpenFileDialog.Names



alibaqdadloo
سه شنبه 19 آبان 1394, 21:35 عصر
سلام دوستان
میخوام با file dialog چند فایل رو انتخاب کنم
نمیدونم چی برمیگردونه و مقداری که برمیگرده رو چطوری باید دریافت کنم و ازش استفاده کنم
مثلا با این کد میشه یه مقدار دریافت کرد و تو متغیر file path ریخت
string filePath = OpenFileDialog.FileName
ولی اگه بشه OpenFileDialog.FileNames =????

mr_ayma
چهارشنبه 20 آبان 1394, 16:14 عصر
سلام ، شما باید Multiselect رو برابر true قرار بدین ، اینجا (https://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.multiselect%28 v=vs.110%29.aspx)یه مثال از MSDN هست که من یه کوچولو براتون تغییرش دادم چون احساس کردم درکش راحت تر میشه

تو رویداد لود قرم این کدها رو بنوسید




this.openFileDialog1.Filter =
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
"All files (*.*)|*.*";

// Allow the user to select multiple images.
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "My Image Browser";



و روی رویداد کلیک یک دکمه هم




int i = 0;
DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
// Read the files
foreach (String file in openFileDialog1.FileNames)
{
// Create a PictureBox.
try
{
MessageBox.Show(openFileDialog1.FileNames[i]);
i++;
}
catch (SecurityException ex)
{
// The user lacks appropriate permissions to read files, discover paths, etc.
MessageBox.Show("Security error. Please contact your administrator for details.\n\n" +
"Error message: " + ex.Message + "\n\n" +
"Details (send to Support):\n\n" + ex.StackTrace
);
}
catch (Exception ex)
{
// Could not load the image - probably related to Windows file system permissions.
MessageBox.Show("Cannot display the image: " + file.Substring(file.LastIndexOf('\\'))
+ ". You may not have permission to read the file, or " +
"it may be corrupt.\n\nReported error: " + ex.Message);
}
}
}