Write text filename as date in c#How do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Calling the base constructor in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?save page in c# webbrowser without savefiledialogue
What's the difference between 違法 and 不法?
Is there a word to describe the feeling of being transfixed out of horror?
MAXDOP Settings for SQL Server 2014
Is camera lens focus an exact point or a range?
Difference between -| and |- in TikZ
Translation of Scottish 16th century church stained glass
Can I use my Chinese passport to enter China after I acquired another citizenship?
Does the Mind Blank spell prevent the target from being frightened?
Why did the HMS Bounty go back to a time when whales are already rare?
Transformation of random variables and joint distributions
Has Darkwing Duck ever met Scrooge McDuck?
Why do IPv6 unique local addresses have to have a /48 prefix?
How can "mimic phobia" be cured or prevented?
Query about absorption line spectra
Why does Async/Await work properly when the loop is inside the async function and not the other way around?
Is possible to search in vim history?
Diode in opposite direction?
What linear sensor for a keyboard?
Greatest common substring
Is there a conventional notation or name for the slip angle?
If a character with the Alert feat rolls a crit fail on their Perception check, are they surprised?
Varistor? Purpose and principle
Why did the EU agree to delay the Brexit deadline?
Create all possible words using a set or letters
Write text filename as date in c#
How do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Calling the base constructor in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?save page in c# webbrowser without savefiledialogue
So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code
private void btnAdd_Click(object sender, EventArgs e)
using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)
if (sfd.ShowDialog() == DialogResult.OK)
using (StreamWriter sw = new StreamWriter(sfd.FileName))
sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
What I want to know is how I'm meant to preset the filename as a date in this code?
c#
New contributor
add a comment |
So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code
private void btnAdd_Click(object sender, EventArgs e)
using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)
if (sfd.ShowDialog() == DialogResult.OK)
using (StreamWriter sw = new StreamWriter(sfd.FileName))
sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
What I want to know is how I'm meant to preset the filename as a date in this code?
c#
New contributor
Have you already tried something?
– dymanoid
Mar 21 at 13:10
Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN
– Simon Wilson
Mar 21 at 13:11
if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it
– Daniel Brughera
Mar 21 at 14:14
add a comment |
So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code
private void btnAdd_Click(object sender, EventArgs e)
using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)
if (sfd.ShowDialog() == DialogResult.OK)
using (StreamWriter sw = new StreamWriter(sfd.FileName))
sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
What I want to know is how I'm meant to preset the filename as a date in this code?
c#
New contributor
So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code
private void btnAdd_Click(object sender, EventArgs e)
using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)
if (sfd.ShowDialog() == DialogResult.OK)
using (StreamWriter sw = new StreamWriter(sfd.FileName))
sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
What I want to know is how I'm meant to preset the filename as a date in this code?
c#
c#
New contributor
New contributor
edited Mar 21 at 13:09
canton7
4,9061728
4,9061728
New contributor
asked Mar 21 at 13:08
ItsMeJoshItsMeJosh
1
1
New contributor
New contributor
Have you already tried something?
– dymanoid
Mar 21 at 13:10
Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN
– Simon Wilson
Mar 21 at 13:11
if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it
– Daniel Brughera
Mar 21 at 14:14
add a comment |
Have you already tried something?
– dymanoid
Mar 21 at 13:10
Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN
– Simon Wilson
Mar 21 at 13:11
if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it
– Daniel Brughera
Mar 21 at 14:14
Have you already tried something?
– dymanoid
Mar 21 at 13:10
Have you already tried something?
– dymanoid
Mar 21 at 13:10
Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN
– Simon Wilson
Mar 21 at 13:11
Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN
– Simon Wilson
Mar 21 at 13:11
if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it
– Daniel Brughera
Mar 21 at 14:14
if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it
– Daniel Brughera
Mar 21 at 14:14
add a comment |
2 Answers
2
active
oldest
votes
assign the current DateTime to DefaultFileName
property on save file dialog instance
sfd.DefaultFileName=DateTime.Now.ToString();
or
sfd.FileName=DateTime.Now.ToString();
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
add a comment |
string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now);
Console.WriteLine("Path: " + logPath);
using (StreamWriter file = new StreamWriter(@"./" + logPath, true))
file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));
Console.WriteLine("Logs inserted to file");
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281158%2fwrite-text-filename-as-date-in-c-sharp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
assign the current DateTime to DefaultFileName
property on save file dialog instance
sfd.DefaultFileName=DateTime.Now.ToString();
or
sfd.FileName=DateTime.Now.ToString();
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
add a comment |
assign the current DateTime to DefaultFileName
property on save file dialog instance
sfd.DefaultFileName=DateTime.Now.ToString();
or
sfd.FileName=DateTime.Now.ToString();
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
add a comment |
assign the current DateTime to DefaultFileName
property on save file dialog instance
sfd.DefaultFileName=DateTime.Now.ToString();
or
sfd.FileName=DateTime.Now.ToString();
assign the current DateTime to DefaultFileName
property on save file dialog instance
sfd.DefaultFileName=DateTime.Now.ToString();
or
sfd.FileName=DateTime.Now.ToString();
answered Mar 21 at 13:20
AarifAarif
368413
368413
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
add a comment |
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?
– ItsMeJosh
Mar 22 at 0:45
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)
– Aarif
2 days ago
add a comment |
string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now);
Console.WriteLine("Path: " + logPath);
using (StreamWriter file = new StreamWriter(@"./" + logPath, true))
file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));
Console.WriteLine("Logs inserted to file");
add a comment |
string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now);
Console.WriteLine("Path: " + logPath);
using (StreamWriter file = new StreamWriter(@"./" + logPath, true))
file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));
Console.WriteLine("Logs inserted to file");
add a comment |
string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now);
Console.WriteLine("Path: " + logPath);
using (StreamWriter file = new StreamWriter(@"./" + logPath, true))
file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));
Console.WriteLine("Logs inserted to file");
string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now);
Console.WriteLine("Path: " + logPath);
using (StreamWriter file = new StreamWriter(@"./" + logPath, true))
file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));
Console.WriteLine("Logs inserted to file");
answered Mar 21 at 13:47
Mert AkkanatMert Akkanat
1
1
add a comment |
add a comment |
ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.
ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.
ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.
ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281158%2fwrite-text-filename-as-date-in-c-sharp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you already tried something?
– dymanoid
Mar 21 at 13:10
Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN
– Simon Wilson
Mar 21 at 13:11
if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it
– Daniel Brughera
Mar 21 at 14:14