本文整理汇总了C#中OpenFileDialog.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.OpenFile方法的具体用法?C# OpenFileDialog.OpenFile怎么用?C# OpenFileDialog.OpenFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.OpenFile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open_Click
protected void Open_Click(Object sender, EventArgs e)
{
OpenFileDialog o = new OpenFileDialog();
if(o.ShowDialog() == DialogResult.OK) {
Stream file = o.OpenFile();
StreamReader reader = new StreamReader(file);
char[] data = new char[file.Length];
reader.ReadBlock(data,0,(int)file.Length);
text.Text = new String(data);
reader.Close();
}
}
示例2: InitializeStreamBitmap
private void InitializeStreamBitmap()
{
try
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Stream myStream = null;
if ((myStream = openFileDialog1.OpenFile()) != null)
{
bitmap1 = new Bitmap(myStream);
str = openFileDialog1.FileName;
}
}
}
catch (Exception)
{
MessageBox.Show("There was an error opening the image file.");
}
}
示例3: Aplikacja
//konstruktor wczytujący kalendarz z pliku
public Aplikacja()
{
kalendarz = new Kalendarz();
data = new Data_dzien();
while (data.DzienTygodnia() != DniTygodnia.poniedziałek) { data--; }
//inicjalizacja OpenFileDialog
otwórz_plik = new OpenFileDialog();
otwórz_plik.InitialDirectory = "c:\\";
otwórz_plik.FileName = "";
otwórz_plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
otwórz_plik.FilterIndex = 2;
otwórz_plik.RestoreDirectory = true;
//**************KONIEC INICJALIZACJI OpenFileDialog**************
//inicjalizacja SaveFileDialog
zapisz_plik = new SaveFileDialog();
zapisz_plik.AddExtension = true;
zapisz_plik.FileName = "";
zapisz_plik.InitialDirectory = "c:\\";
zapisz_plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
zapisz_plik.FilterIndex = 1;
zapisz_plik.RestoreDirectory = true;
//**************KONIEC INICJALIZACJI SaveFileDialog**************
if (otwórz_plik.ShowDialog() == DialogResult.OK)
{
Stream plik = otwórz_plik.OpenFile();
kalendarz.Wczytaj(plik);
plik.Flush();
plik.Close();
}
}
示例4: btnLoad_Click
private void btnLoad_Click(object sender, EventArgs e)
{
// locals
Stream myStream = null;
OpenFileDialog openFileDialog = new OpenFileDialog();
string lastDirectory = GetRegKey("lastDirectory");
//set up file dialog
openFileDialog.Filter = "SQL Files (*.sql)|*.sql|All files (*.*)|*.*";
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
openFileDialog.InitialDirectory = (lastDirectory == "") ? "c:\\" : lastDirectory;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog.OpenFile()) != null)
{
//show file in ui
txtFileName.Text = openFileDialog.FileName;
//save dir to reg
this.SetRegKey("lastDirectory", Path.GetDirectoryName(openFileDialog.FileName));
LoadChangeList(openFileDialog.FileName);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Problem processing input file.\r\nOriginal error: " + ex.Message);
}
}
}
示例5: manualInstallMod
internal static void manualInstallMod()
{
if (isInstalling)
{
notifier.Notify(NotificationType.Warning, "Already downloading a mod", "Please try again after a few seconds.");
return;
}
isInstalling = true;
using (var dlg = new OpenFileDialog()
{
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "zip",
Filter = "Zip Files|*.zip",
FilterIndex = 1,
Multiselect = false,
Title = "Choose the mod zip to install"
})
{
//user pressed ok
if (dlg.ShowDialog() == DialogResult.OK)
{
//open the file in a stream
using (var fileStream = dlg.OpenFile())
{
ZipFile zip = new ZipFile(fileStream);
//check integrity
if (zip.TestArchive(true))
{
//look for the map file. It contains the mod name
ZipEntry map = zip.Cast<ZipEntry>().FirstOrDefault(a => a.Name.ToLower().EndsWith(".bsp"));
if (map != null)
{
//look for the version file
int entry = zip.FindEntry("addoninfo.txt", true);
if (entry >= 0)
{
string allText = string.Empty;
using (var infoStream = new StreamReader(zip.GetInputStream(entry)))
allText = infoStream.ReadToEnd();
string version = modController.ReadAddonVersion(allText);
if (!string.IsNullOrEmpty(version))
{
Version v = new Version(version);
string name = Path.GetFileNameWithoutExtension(map.Name).ToLower();
//check if this same mod is already installed and if it needs an update
if (modController.clientMods.Any(
a => a.name.ToLower().Equals(name) && new Version(a.version) >= v))
{
MessageBox.Show("The mod you are trying to install is already installed or outdated.", "Mod Manual Install",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
string targetDir = Path.Combine(d2mpDir, name);
if (Directory.Exists(targetDir))
Directory.Delete(targetDir, true);
//Make the dir again
Directory.CreateDirectory(targetDir);
if (UnzipWithTemp(null, fileStream, targetDir))
{
refreshMods();
log.Info("Mod manually installed!");
notifier.Notify(NotificationType.Success, "Mod installed", "The following mod has been installed successfully: " + name);
var mod = new ClientMod() {name = name, version = v.ToString()};
var msg = new OnInstalledMod() {Mod = mod};
Send(JObject.FromObject(msg).ToString(Formatting.None));
var existing = modController.clientMods.FirstOrDefault(m => m.name == mod.name);
if (existing != null) modController.clientMods.Remove(existing);
modController.clientMods.Add(mod);
}
else
{
MessageBox.Show("The mod could not be installed. Read the log file for details.", "Mod Manual Install",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
else
{
MessageBox.Show("Could not read the mod version from the zip file.", "Mod Manual Install",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
MessageBox.Show("No mod info was found in the zip file.", "Mod Manual Install",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//.........这里部分代码省略.........
示例6: Wczytaj
public void Wczytaj()
{
OpenFileDialog plik = new OpenFileDialog();
plik.InitialDirectory = ".";
plik.FileName = "";
plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
plik.FilterIndex = 1;
plik.RestoreDirectory = true;
if (plik.ShowDialog() == DialogResult.OK)
{
Stream plik_stream=plik.OpenFile();
kalendarz.Wczytaj(plik_stream);
plik_stream.Flush();
plik_stream.Close();
}
}
示例7: Wczytaj
public void Wczytaj()
{
kalendarz = new Kalendarz();
otwórz_plik = new OpenFileDialog();
otwórz_plik.InitialDirectory = "c:\\";
otwórz_plik.FileName = "";
otwórz_plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
otwórz_plik.FilterIndex = 2;
otwórz_plik.RestoreDirectory = true;
if (otwórz_plik.ShowDialog() == DialogResult.OK)
{
Stream plik = otwórz_plik.OpenFile();
kalendarz.Wczytaj(plik);
plik.Flush();
plik.Close();
}
}
示例8: Open
private void Open()
{
System.IO.Stream stream;
OpenFileDialog dialog;
dialog = new OpenFileDialog();
dialog.Filter = "XML files (*.xml)|*.xml";
dialog.FilterIndex = 1;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK) {
if ((stream = dialog.OpenFile()) != null) {
_scene.Reset ();
_doc.Load (stream);
stream.Close ();
}
}
}
示例9: FileOpen
private void FileOpen()
{
DefaultSettings settings = DefaultSettings.Instance;
Stream myStream;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = settings.DefaultTemplateDirectory;
openFileDialog.Filter = PROJECT_FILE_TYPES + TemplateEditor.FILE_TYPES;
openFileDialog.FilterIndex = TemplateEditor.DEFAULT_OPEN_FILE_TYPE_INDEX + 1;
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
myStream = openFileDialog.OpenFile();
if (null != myStream)
{
myStream.Close();
foreach (string filename in openFileDialog.FileNames)
{
int extindex = filename.LastIndexOf(".");
if (extindex >= 0)
{
FileInfo f = new FileInfo(filename);
if (f.Exists)
{
AddRecentFile(f.FullName);
string ext = filename.Substring(extindex);
bool validProjectExt = false;
foreach (string vpe in validProjectExtentions)
{
if (vpe == ext)
validProjectExt = true;
}
if (validProjectExt)
{
this.OpenProjectEditor(filename);
}
else
{
this.OpenTemplateEditor(filename);
}
}
}
}
}
}
}
示例10: bt_browse_Click
private void bt_browse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
Stream myStream = null;
openFileDialog1.InitialDirectory = path + "\\media\\BasicHomeBG";
openFileDialog1.Filter = "PNG files (*.png)|*.png|JPG files (*.jpg)|*.jpg";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
if (System.IO.Directory.Exists(path))
{
System.IO.File.Copy(openFileDialog1.FileName, path + "\\media\\BasicHomeBG\\" + openFileDialog1.SafeFileName, true);
}
new_bgimage.Text = openFileDialog1.SafeFileName;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
示例11: button1_Click_1
private void button1_Click_1(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error:\n" + ex.Message.ToString());
}
}
}
示例12: uiLoadResults_ItemClick
/// <summary>
/// Uncompress (gzip) and deserialize a file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiLoadResults_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var browser = new OpenFileDialog();
browser.DefaultExt = "findResults";
browser.Filter = "find results|*.findResults|All Files|*.*";
browser.Title = "Open find results";
if (browser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var ser = new XmlSerializer(typeof(FindResults));
using (var file = browser.OpenFile())
using(var gzip = new GZipStream(file, CompressionMode.Decompress))
findResults = (FindResults)ser.Deserialize(gzip);
gridControl1.DataSource = findResults.Found;
uiFoundCount.Caption = string.Format("Found {0} items in {1} files", findResults.Found.Count, findResults.FilesSearched);
}
}
示例13: AuthorizeAndUpload
/// <summary>
/// This is the worker method that executes when the user clicks the GO button.
/// It illustrates the workflow that would need to take place in an actual application.
/// </summary>
public static void AuthorizeAndUpload()
{
// First, create a reference to the service you wish to use.
// For this app, it will be the Drive service. But it could be Tasks, Calendar, etc.
// The CreateAuthenticator method is passed to the service which will use that when it is time to authenticate
// the calls going to the service.
_service = new DriveService(CreateAuthenticator());
// Open a dialog box for the user to pick a file.
OpenFileDialog dialog = new OpenFileDialog();
dialog.AddExtension = true;
dialog.DefaultExt = ".txt";
dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
dialog.Multiselect = false;
dialog.ShowDialog();
File body = new File();
body.Title = System.IO.Path.GetFileName(dialog.FileName);
body.Description = "A test document";
body.MimeType = "text/plain";
System.IO.Stream fileStream = dialog.OpenFile();
byte[] byteArray = new byte[fileStream.Length];
fileStream.Read(byteArray, 0, (int)fileStream.Length);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
// Get a listing of the existing files...
List<File> fileList = GoogleDrive.Util.Utilities.RetrieveAllFiles(_service);
// Set a flag to keep track of whether the file already exists in the drive
bool fileExists = false;
foreach (File item in fileList)
{
if (item.Title == body.Title)
{
// File exists in the drive already!
fileExists = true;
DialogResult result = MessageBox.Show("The file you picked already exists in your Google Drive. Do you wish to overwrite it?", "Confirmation", System.Windows.Forms.MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
// Yes... overwrite the file
GoogleDrive.Util.Utilities.UpdateFile(_service, item.Id, item.Title, item.Description, item.MimeType, dialog.FileName, true);
}
else if (result == DialogResult.No)
{
// MessageBoxResult.No code here
GoogleDrive.Util.Utilities.InsertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
}
else
{
// MessageBoxResult.Cancel code here
return;
}
break;
}
}
// Check to see if the file existed. If not, it is a new file and must be uploaded.
if (!fileExists)
{
GoogleDrive.Util.Utilities.InsertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
}
System.Windows.Forms.MessageBox.Show("Upload Complete");
}