Search Results

Search found 34 results on 2 pages for 'savefiledialog'.

Page 1/2 | 1 2  | Next Page >

  • SaveFileDialog problem (C#) (VS2008)

    - by typoknig
    Hi all, I am having an issue with SaveFileDialog for some reason. All I want to do is extract data from a text box line by line and write it to a text file, then save that text file to the desktop. The first bit of code works fine (though it doesn't save to the desktop). The second bit of code is what I want to use, but when it creates the text file the text file is empty. What did I do wrong in my second bit of code? This code works, but it does not save to the desktop and it isn't as nice as the second code. //When the Save button is clicked the contents of the text box will be written to a text file. private void saveButton_Click(object sender, EventArgs e) { int textBoxLines = textBox.Lines.Count(); if (File.Exists(saveFile)) { result = MessageBox.Show("The file " + saveFile + " already exists.\r\nDo you want to replace it?", "File Already Exists!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { TextWriter tw1 = new StreamWriter(saveFile); for (int i = 0; i < textBoxLines; i++) { tw1.WriteLine(textBox.Lines.GetValue(i)); } tw1.Close(); } if (result == DialogResult.No) { MessageBox.Show("Please move or rename existing " + saveFile + "\r\nBefore attempting to save again.", "Message"); } } else { TextWriter tw2 = new StreamWriter(saveFile); for (int i = 0; i < textBoxLines; i++) { tw2.WriteLine(textBox.Lines.GetValue(i)); } tw2.Close(); } } This code does not work, but it is what I want to use. //When the Save button is clicked the contents of the text box will be written to a text file. private void saveButton_Click(object sender, EventArgs e) { int textBoxLines = textBox.Lines.Count(); Stream saveStream; SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; saveDialog.FilterIndex = 2; saveDialog.RestoreDirectory = true; saveDialog.FileName = (saveFile); saveDialog.InitialDirectory = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); if (saveDialog.ShowDialog() == DialogResult.OK) { if ((saveStream = saveDialog.OpenFile()) != null) { StreamWriter tw = new StreamWriter(saveStream); for (int i = 0; i < textBoxLines; i++) { tw.WriteLine(textBox.Lines.GetValue(i)); } saveStream.Close(); } } }

    Read the article

  • Issue while saving image using savefiledialog

    - by user1097772
    I'm using savefiledialog to save an image. Canvas is picturebox and the loaded image is bitmap. When I try to save it the file is created but somehow corrupted. Cause when I try againt load the image or show in different viewer it doesn't work - I mean the saved file is corrupted. There is an method for saving image. private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) { System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile(); try { switch (saveFileDialog1.FilterIndex) { case 1: canvas.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp); break; case 2: canvas.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg); break; case 3: canvas.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png); break; case 4: canvas.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Tiff); break; } } catch (Exception ex) { System.Console.WriteLine("Exception " + ex); } I should also mention the property Filter. saveFileDialog1.Filter has value: bmp (*.bmp)|*.bmp|jpeg (*.jpeg)|*.jpeg|png (*.png)|*.png|tiff (*.tiff)|*.tiff

    Read the article

  • Save Dialog on top of another custom dialog is behaving strangely!

    - by Raghu
    I have a save as image feature for charts in my application. The chart control is a custom user control with custom logic in them. It also has some scaling based on size, zoom etc. However, while saving them as an image I would like to give the user the option to set the size of the image (eg: 800x600 px @ 300 DPI). To do this I have created a Form with textboxes/checkboxes etc for various settings for image. One of these TextBoxes is for the file name. The file name textbox is readonly and is accompanied with a browse button which shows a SaveFileDialog when clicked. The user clicks "Save As Image" in the main form's menu. I show the ImageExportDialog using the code below: using(ImageExportDialog dlg = new ImageExportDialog()) { if(dlg.ShowDialog() == DialogResult.OK) { //get the settings selected by the user and generate the image } } In the ImageExportDialog, the user clicks on the browse button and the SaveFileDialog is shown as follows: using(SaveFileDialog dlg = new SaveFileDialog()) { if(dlg.ShowDialog() == DialogResult.OK) { txtFileName.Text = dlg.FileName; } } Now the problem is, when the user clicks on "Save" button in the SaveFileDialog, as expected the txtFileName.Text is set, but the parent custom dialog also seems to return from the ShowDialog method and the DialogResult is the same as the one for SaveFileDialog! The control then goes on to the "get the settings selected by the user and generate the image" part of the code above. Not really sure what I am doing wrong here!

    Read the article

  • Allow selection of readonly files from SaveFileDialog?

    - by Andy Dent
    I'm using Microsoft.Win32.SaveFileDialog in an app where all files are saved as readonly but the user needs to be able to choose existing files. The existing files being replaced are renamed eg: blah.png becomes blah.png-0.bak, blah.png-1.bak and so on. Thus, the language for the OverwritePrompt is inappropriate - we are not allowing them to overwrite files - so I'm setting dlog.OverwritePrompt = false; The initial filenames for the dialog are generated based on document values so for them, it's easy - we rename the candidate file in advance and if the user cancels or chooses a different name, rename it back again. When I delivered the feature, testers swiftly complained because they wanted to repeatedly save files with names different from the agreed workflow (those goofy, playful guys!). I can't figure out a way to do this with the standard dialogs, in a way that will run safely on both XP (for now) and Windows 7. I was hoping to hook into the FileOK event but that is called after I get a warning dialog: |-----------------------------------------| | blah.png | | This file is set to read-only. | | Try again with a different file name. | |-----------------------------------------|

    Read the article

  • How do I save my whole program?

    - by user1444829
    What argument should be in this missing part of formatter.Serliaze to get the program to save just the program as a .exe? Ignore the Openfiles. class FileOption { OpenFileDialog openDialog = new OpenFileDialog(); SaveFileDialog saveDialog = new SaveFileDialog(); BinaryFormatter formatter = new BinaryFormatter(); public void Open() { } public void Save() { if (saveDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(saveDialog.FileName, FileMode.Create); formatter.Serialize(file, x); // x means that i havent set anything there yet// file.Close(); } } }

    Read the article

  • How to save a picture from a partial trust XBAP app?

    - by Yacoder
    I have an XBAP app, which shows some pictures, and my users would like to save some of them to disk. But my XBAP app runs in the partial trust mode, so it can't initiate SaveFileDialog, not to mention it can't access the File System. What's would be the Stack Overflow recommended way to save a pic to disk in this case?

    Read the article

  • Visual Studio 2008 "Save File As" Dialog Intermittent Issue

    - by Jerad Rose
    Me and a few of my coworkers are experiencing an odd issue in Visual Studio 2008 and Windows 7 (64-bit). We use VSS6 for our source control (unfortunately). We have an issue where we will make a change to a checked-out file, resulting in the file getting checked out as expected. But when we go to build the project, or try to save the file, it will often (but not always) prompt us with the "Save File As" dialog, as if VS thinks the file is checked-in (and thus has the read-only flag set). However, all we have to do is cancel out of the dialog and save or build again, and it will always work the second time, without prompting the save as dialog. Or, we can go through with the save as, leaving the name the same, and it will work. It's as if the source control status in VS2008 hasn't caught up w/ VSS (even though we VS2008 was the app that checked the file out). This is similar to the discussion on this thread, but it's not an issue of permissions or running as administrator, 1) because it resolves itself on second attempt, and 2) we're already running VS as administrator. Thanks in advance. Jerad

    Read the article

  • Has anyone noticed that a WPF file dialog will pass a click through to the UI when double clicking t

    - by Ben
    I have some buttons on my WPF UI and I also need to choose files from time to time. I kept noticing strange problems where when I double-click an item in the file dialog, a button on the main UI would also get clicked. After experimenting, it seems that if you line up an item in the file dialog with a button behind it on the main UI and double click to select the file, it will single-click the button behind it as well. Has anyone else noticed this, or is it just a freak bug with the way I have my UI laid out?

    Read the article

  • When Does the File Download Dialog Open? - HTML, Javascript

    - by sahs-i-muhterem
    Hello, I have a html page, and when I click a file link on the page, the file download dialog pops up, and this file dialog locks the page. I mean without selecting one of the choices(Open, Save, Cancel) I can't do anything on the page (which is normal). What I need is if javascript can check whether the page is locked or not. (or whether the file dialog is popped?) p.s. don't say "put an onclick event to the link", because the server may respond very slowly (like 30 seconds after clicking)

    Read the article

  • Has anyone noticed that a WPF file dialog will pass through a click to the UI when double clicking t

    - by Ben
    I have some buttons on my WPF UI and I also need to choose files from time to time. I kept noticing strange problems where when I double-click an item in the file dialog, a button on the main UI would also get clicked. After experimenting, it seems that if you line up an item in the file dialog with a button behind it on the main UI and double click to select the file, it will single-click the button behind it as well. Has anyone else noticed this, or is it just a freak bug with the way I have my UI laid out?

    Read the article

  • Opening response stream in silverlight

    - by John Maloney
    Hello, I am attempting to return a image from a server using Silverlight 3. The server returns the Response stream like this: context.Response.ContentType = imageFactory.ContentType imgStream.WriteTo(context.Response.OutputStream) imgStream.Close() context.Response.End() On the Silverlight client I am handling the stream like: Dim request As HttpWebRequest = result.AsyncState Dim response As HttpWebResponse = request.EndGetResponse(result) Dim responseStream As IO.Stream = response.GetResponseStream() I want to take that stream and open the browsers save dialog, one option I have explored is using the Html.Window.Navigate(New Uri("image url")) and this opened the correct browser default dialog but it is not an option because I need to send extended information(e.g. XML) to the server through the HttpRequest.Headers.Item and the Navigate doesn't allow this. How can I take a Response Stream and force the default browser Save dialog to appear from the Silverlight Application without using the Html.Window.Navigate(New Uri("image url"))?

    Read the article

  • How do I save a file generated by an OS X Dashboard Widget?

    - by Weston C
    I've got a web app that I'm porting to an OS X Dashboard widget. The web app generates some data on the client side using JavaScript, and then, when the user wants to save it, sends it to a server-side script which relays the data back with the Content-disposition: attachment; HTTP header, triggering a save-file dialog in most browsers. I've tried duplicating this in the Dashboard environment. The Widget simply disappears. I don't know, but I suspect that it may be actually navigating to the unfamiliar content. So, how do I trigger a "save file dialog" -- or, failing that, use any method at all to save the data the Widget generates as a file?

    Read the article

  • .NET Web Browser Control - SaveAs Event

    - by Dale
    Does anybody know if you can access the SaevFileDialog control that's used by the WebBrowser control? Once somebody saves the webpage being displayed I need to catch where the files have been created; however I can't seem to find any events/members that allow me access to that information.

    Read the article

  • AppleScript to click "Don't Save" on window close

    - by dsg
    I am using AppleScript to close windows in Google Sketchup as follows: $ osascript -e 'tell application "SketchUp" to close window 1' When I close the window, the program prompts me to save, and there is a dialog box with buttons "Don't Save", "Cancel", and "Save...". How do I make my script click on the "Don't Save" button in this situation? Also, if there is a better way of closing the window, I'm all ears.

    Read the article

  • Changing/Adding controls to the windows Open/Save common dialog

    - by ajp
    Is there a way of changing/adding to the windows Open/Save common dialog to add extra functionality? At work we have an area on a server with hundreds of 'jobfolders'- just ordinary windows folders created/managed automatically by the database application to house information about a job (emails/scanned faxes/Word docs/Spreadsheets/Photos etc) The folders are named by the job Number. I would like to expand the standard open/save dialog with a combobox which searches for jobfolders based on tags from the database, so that whatever my users are doing they can easily find their way to the correct jobfolder to find/save their work Connecting to the database and providing the functionality to search is no problem, but is there a way to add a combobox control (ideally with a keypress/keydown event) to the dialog? Or Create my own dialog and have it called/used in place of the standard one? i.e. from ANY app my dialog would be called allowing easy access to the jobfolders. If they are in outlook they can find a jobfolder quickly, if there are using Notepad they can still find the folder easily. This would mean a new unified way of finding jobfolders from any app. Ideally someone would know a way using VB/VB.net/C# but I'm guessing, if its possible, its probably going to be C++.

    Read the article

  • Why does this IF statement fail?

    - by ChosenOne
    If variable path is empty, and editor.Text is not empty, the SaveFileDialog should be displayed. Now, why on earth is this damn thing failing??? I have tried this with many different variations of code with the same result: FAIL: if(path.Length >= 1) // path contains a path. Save changes instead of creating NEW file. { File.WriteAllText(path, content); } else { // no path defined. Create new file and write to it. using(SaveFileDialog saver = new SaveFileDialog()) { if(saver.ShowDialog() == DialogButtons.OK) { File.WriteAllText(saver.Filename, content); } } } At the top of code file I have: path = String.Empty; So why the heck it this failing every single time, even after trying all of the below variations? if(path.Length > 1) // path contains a path. Save changes instead of creating NEW file. { File.WriteAllText(path, content); } else { // no path defined. Create new file and write to it. using(SaveFileDialog saver = new SaveFileDialog()) { if(saver.ShowDialog() == DialogButtons.OK) { File.WriteAllText(saver.Filename, content); } } } and if(String.IsNullOrEmpty(path)) // path contains a path. Save changes instead of creating NEW file. { File.WriteAllText(path, content); } else { // no path defined. Create new file and write to it. using(SaveFileDialog saver = new SaveFileDialog()) { if(saver.ShowDialog() == DialogButtons.OK) { File.WriteAllText(saver.Filename, content); } } } and if(String.IsNullOrWhiteSpace(path)) // path contains a path. Save changes instead of creating NEW file. { File.WriteAllText(path, content); } else { // no path defined. Create new file and write to it. using(SaveFileDialog saver = new SaveFileDialog()) { if(saver.ShowDialog() == DialogButtons.OK) { File.WriteAllText(saver.Filename, content); } } } This is making me very angry. How could this fail? Setting a break point reveals that path is definitely null/"".

    Read the article

  • Save as DialogBox to save textbox content to a newfile using asp.net

    - by user195114
    I want the users to type their text in the given textbox and on clicking on createNewFile Button, a SaveAs Dialogbox should popup and the users should browse through the location and save the file as desired. I have tried some thing but (1) the dialog box goes behind the application (2) when run, dialogbox opens 3 times, means it executes 3 times REPLY TO THE POST protected void btnNewFile_Click(object sender, EventArgs e) { StreamWriter sw = null; try { SaveFileDialog sdlg = new SaveFileDialog(); DialogResult result = sdlg.ShowDialog(); sdlg.InitialDirectory = @"C:\"; sdlg.AddExtension = true; sdlg.CheckPathExists = true; sdlg.CreatePrompt = false; sdlg.OverwritePrompt = true; sdlg.ValidateNames = true; sdlg.ShowHelp = true; sdlg.DefaultExt = "txt"; // sdlg.ShowDialog = Form.ActiveForm; string file = sdlg.FileName.ToString(); string data = txtNewFile.Text; if (sdlg.ShowDialog() == DialogResult.OK) { sw.WriteLine(txtNewFile.Text); sw.Close(); } if (sdlg.ShowDialog() == DialogResult.Cancel) { sw.Dispose(); } //Save(file, data); } catch { } finally { if (sw != null) { sw.Close(); } } } private void Save(string file, string data) { StreamWriter writer = new StreamWriter(file); SaveFileDialog sdlg1 = new SaveFileDialog(); try { if (sdlg1.ShowDialog() == DialogResult.OK) { writer.Write(data); writer.Close(); } else writer.Dispose(); } catch (Exception xp) { MessageBox.Show(xp.Message); } finally { if (writer != null) { writer.Close(); } } } I have tried this.

    Read the article

  • Save image in Windows Mobile 5.0 using C#

    - by Vijay V
    Hi I am saving image in windows mobile application using C#.My code is SaveFileDialog dialog = new SaveFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { aspectRatioPictureBox1.Photo.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp); } In the above code i am able to save only in folders of MyDocument But i am not able to browse to save in other folders.. Please let know the code to save image through browsing the location Thanks in Advance

    Read the article

  • Problem with saving pictures in certain ways [migrated]

    - by user132750
    I am making a Garfield comic viewer in C#. I have a button that saves the comic on screen to the computer. However, when I compile it from Visual C# Express, it saves perfectly. When I run the exe file from the directory, I get an unhandled exception message stating "A generic error occurred in GDI+". Here is my saving code: private void save_Click(object sender, EventArgs e) { using (SaveFileDialog sfdlg = new SaveFileDialog()) { sfdlg.Title = "Save Dialog"; sfdlg.Filter = "Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*"; if (sfdlg.ShowDialog(this) == DialogResult.OK) { using (Bitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height)) { pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); pictureBox1.Image = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height); pictureBox1.Image.Save("c://cc.Jpg"); bmp.Save(sfdlg.FileName); pictureBox1.ImageLocation = "http://garfield.com/uploads/strips" + "/" + whole.ToString("yyyy-MM-dd") + ".jpg"; MessageBox.Show("Comic Saved."); } } } } What can I do?

    Read the article

  • WPF to XPS in landscape orientation

    - by Felix
    Hello, i am trying to to generate a XPS Document from a WPF Control. Printing works so far, but i cannot find a way to create the XPS in landscape mode. My code to create the XPS file, mostly taken from another SO page public FixedDocument ReturnFixedDoc() { FixedDocument fixedDoc = new FixedDocument(); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); var ctrl = new controlToPrint(); //Create first page of document fixedPage.Children.Add(ctrl); ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); //Create any other required pages here return fixedDoc; } public void SaveCurrentDocument() { // Configure save file dialog box Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "MyReport"; // Default file name dlg.DefaultExt = ".xps"; // Default file extension dlg.Filter = "XPS Documents (.xps)|*.xps"; // Filter files by extension // Show save file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { // Save document string filename = dlg.FileName; FixedDocument doc = ReturnFixedDoc(); XpsDocument xpsd = new XpsDocument(filename, FileAccess.Write); System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd); xw.Write(doc); xpsd.Close(); } } Any help is appreciated.

    Read the article

  • LPCSTR, TCHAR, String

    - by user285327
    I am use next type of strings: LPCSTR, TCHAR, String i want to convert: 1) from TCHAR to LPCSTR 2) from String to char I convert from TCHAR to LPCSTR by that code: RunPath = TEXT("C:\\1"); LPCSTR Path = (LPCSTR)RunPath; From String to char i convert by that code: SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog; saveFileDialog1->Title = "?????????? ?????-????????"; saveFileDialog1->Filter = "bck files (*.bck)|*.bck"; saveFileDialog1->RestoreDirectory = true; pin_ptr<const wchar_t> wch = TEXT(""); if ( saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK ) { wch = PtrToStringChars(saveFileDialog1->FileName); } else return; ofstream os(wch, ios::binary); My problem is that when i set "Configuration Properties - General Character Set in "Use Multi-Byte Character Set" the first part of code work correctly. But the second part of code return error C2440. When i set "Configuration Properties - General Character Set in "Use Unicode" the second part of code work correctly. But the first part of code return the only first character from TCHAR to LPCSTR.

    Read the article

  • Save Bitmap image in a location in C#

    - by acadia
    Hello, I have this function to store the bmp image in a desired location as shown below My question is, how do I save the image in C:\temp folder by default, instead of opening the filedialog box? I want to specify sd.fileName=picname+".bmp" and store it in c:\temp by default. I tried to specify Thanks for your help in advance. I tried to public static bool SaveDIBAs( string picname, IntPtr bminfo, IntPtr pixdat ) { SaveFileDialog sd = new SaveFileDialog(); sd.FileName = picname; sd.Title = "Save bitmap as..."; sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|GIF file (*.gif)|*.gif|All files (*.*)|*.*"; sd.FilterIndex = 1; if( sd.ShowDialog() != DialogResult.OK ) return false; Guid clsid; if( ! GetCodecClsid( sd.FileName, out clsid ) ) { MessageBox.Show( "Unknown picture format for extension " + Path.GetExtension( sd.FileName ), "Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information ); return false; } IntPtr img = IntPtr.Zero; int st = GdipCreateBitmapFromGdiDib( bminfo, pixdat, ref img ); if( (st != 0) || (img == IntPtr.Zero) ) return false; st = GdipSaveImageToFile( img, sd.FileName, ref clsid, IntPtr.Zero ); GdipDisposeImage( img ); return st == 0; }

    Read the article

1 2  | Next Page >