TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sangram Mohanty
NA
5
749
unable to create/save a file using SaveFileDialog in WPF
Sep 13 2017 7:13 AM
I am designing a WPF application that is able to create a new .txt file in a desired location, edit it by inserting contents in a textblock, and then saving it. However I am unable to create a new file and unable to save it in a desired location.
I am using commands like SaveFileDialog, Filestream as below: -
private SaveFileDialog newFileDialog = null;\\Inside public partial class MainWindow : Window
newFileDialog = new SaveFileDialog();\\ Inside public MainWindow() to create an object
newFileDialog.FileOk += newFileDialogFileOk
;\\ public MainWindow() to call the function
saveFileDialog.Filter = "All items | *.*";\\ Inside function private void newFile(object sender, RoutedEventArgs e)... These are event driven functions
saveFileDialog.ShowDialog();\\ Inside function private void newFile(object sender, RoutedEventArgs e)
... These are event driven functions
/*Inside function private void newFileDialogFileOk*/
string filefullpath = saveFileDialog.FileName;
FileInfo sr = new FileInfo(filefullpath);
if (sr.Exists)
\{
sr.Replace(filefullpath, filefullpath);
}
else
\{
using (FileStream reader = sr.Create())
\{
Byte[] txt = new UTF8Encoding(true).GetBytes("");
reader.Write(txt, 0, txt.Length);
Attachment:
FileMenu.zip
Reply
Answers (
1
)
WPF get children from layout by name
SVG image format convert to GeometryDrawingBrush Geometry