Basically I'm trying to set the SaveFileDialog's filter like let's say to... "Xml Document (.asdf.xml)|.asdf.xml". It'll filter the files correctly when picking a file, but when actually saving the 开发者_JAVA百科file it only saves as a ".xml". Is this even supported?
I also can't think of a suitable workaround as most workarounds seem to involve needing to manually change the filename without the user knowing about it.
SupportMultiDottedExtensions = true;
Did you try this?
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "XML File (*.asdf.xml)|*.asdf.xml|All Files|";
sfd.SupportMultiDottedExtensions = true;
I took a stab at creating a quick win form using the SaveFileDialog and I was able to get a file to save with a multi-dot extension without issue. I'm using VS2010 and C#. Here's my code for a button click event handler:
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "Xml Document (.asdf.xml)|*.asdf.xml";
saveFileDialog1.ShowDialog();
System.IO.FileStream fs = saveFileDialog1.OpenFile() as System.IO.FileStream;
fs.Write(new byte[] { }, 0, 0);
fs.Close();
}
It worked whether my filter used *.asdf.xml
or .asdf.xml
.
How is your code different? If it's the same, are you creating a new file or overwriting an existing one? I'm not sure what else would be different without seeing your code.
EDIT/UPDATE: Just saw sgrassie's answer about setting SupportMultiDottedExtension. I didn't set it, so maybe it defaults to true in C#/.NET 4.
HTH!
精彩评论