I have a Save button that makes a query to a server which returns a filepath for an email on a shared drive, like "F:storeemail1.eml"
private void SaveAsBtn_Click(object sender, RoutedEventArgs e)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
connection.Open();
using (var cmd = new SqlCommand("spGetDoc", connection) { CommandType = System.Data.CommandType.StoredProcedure })
{
SqlParameter param = new SqlParameter("@GUID", ConfirmedGuidBox.Text);
cmd.Parameters.Add(param);
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
string fileSource = rdr.GetString(1);
Stream myStream;
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Emails|*.eml";
saveFileDialog.FileName = fileSource;
saveFileDialog.ShowDialog();
}
}
}
}
}
This opens a SaveAs dialog as expected, but I can't get it to load the file correctly. The preset filename evaluates to \serverstoreemail1.eml
c#, which if you click Save on will attempt to save the file in the same shared location, rather than the location navigated to inside the Dialog. Shortening the full path to just email1.eml
means nothing gets saved.
It appears saveFileDialog.FileName
doesn't actually open the file in fileSource
, just sets the default name. How can I get this to work, so that I'm able to save a copy of the file specified in the database query?
question from:
https://stackoverflow.com/questions/65926042/saveas-dialog-not-saving-file-from-network-location 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…