Немного хакерский, но работает:
<?php
$date = new DateTime("-6 months");
$date->modify("-" . ($date->format('j')-1) . " days");
echo $date->format('j, F Y');
?>
Dim myString = "Hello world!"
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
saveFileDialog.FilterIndex = 2
saveFileDialog.RestoreDirectory = True
If saveFileDialog.ShowDialog() = DialogResult.OK Then
If saveFileDialog.FileName <> "" Then
System.IO.File.WriteAllText(saveFileDialog.FileName, myString)
End If
End If
There's not a whole lot to it. Specify the file types to save as (in a fairly arcane format; review the docs for the Filter property to learn more), then show the dialog, and either a) retrieve the stream to write to (as shown here) with the OpenFile
method, or retrieve the filename selected with the FileName
property.
Review the docs on MSDN for more.
Here's an example from my project. I start the SFD in the user's my documents folder because they have guaranteed write access there.
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = suggestedName + ".csv";
sfd.Title = "Choose Location For CSV";
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (sfd.ShowDialog() != DialogResult.OK)
{
return;
}
string outputFileName = sfd.FileName;
oh ok, then i should rephrase my question. at runtime i am creating a string and i want to save this string as a file. how do i do this?
Dim theStringToSave as String = "some string here"
Dim sfd As New SaveFileDialog()
sfd.Filter = "txt files (*.txt)|*.txt|(*.csv)|*.csv|All files (*.*)|*.*"
sfd.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
File.WriteAllText(sfd.FileName, theStringToSave)
End If