Hi,
I am using Silverligt 4 application. When I export by default file name should display in the save dialogue box. Please give me a c# code to achieve this in Silverlight 4 application. This is very high priority else give me alternate solution to achive in Silverlight 4 application.
Regards,
Santosh
Answer: 1
That feature was added to the SaveFileDialog control in silverlight 5. Here is a possible work around for silverlight 4 (I did not test):
http://stackoverflow.com/questions/8316799/silverlight-savefiledialog-set-default-file-name
Answer: 2
http://msdn.microsoft.com/en-us/library/system.windows.controls.savefiledialog%28v=vs.95%29.aspx
http://forums.silverlight.net/t/117702.aspx
Answer: 3
hi santoshhegde
private void nmrButton_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.GetType().GetMethod("set_DefaultFileName").Invoke(dialog, new object[] { "FileName.ext" });
dialog.ShowDialog();
}
Thanks & Regards
Mastan Narravula
Mark as Answer", if it helped you or it might help others too.
Answer: 4
Hi,
This I tried I am getting object refernce not set to an instance of an object error.
Regards,
Santosh
Answer: 5
hi
can u tell which item is getting null here...
Answer: 6
I have done like this:
SaveFileDialog objSFD = new SaveFileDialog() {
DefaultExt = "csv",
Filter = "CSV Files (*.csv)|*.csv|Excel XML (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
string item = TextBox.Text;
objSFD.GetType().GetMethod(item).Invoke(objSFD, new object[] { item });
Here item will contain text box value that value I want to keep as SaveDialogueBox default file name. Let me know where I am doing wrong.
Regards,
Santosh
Answer: 7
hi santoshhegde keep this and try
objSFD.GetType().GetMethod("set_DefaultFileName").Invoke(objSFD, new object[] { "Mastan" });
Thanks & Regards
Mastan Narravula
Mark as Answer", if it helped you or it might help others too.
Answer: 8
Hi,
With that also I am getting same error : Object reference not set to an instance of an object.
Answer: 9
hi try this
private void nmrButton_Click(object sender, RoutedEventArgs e)
{
TextBox tb = new TextBox();
tb.Text = "NMR";
SaveFileDialog objSFD = new SaveFileDialog()
{
DefaultExt = "csv",
Filter = "CSV Files (*.csv)|*.csv|Excel XML (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
string item = tb.Text;
objSFD.GetType().GetMethod("set_DefaultFileName").Invoke(objSFD, new object[] { item.ToString() });
objSFD.ShowDialog();
}
Thanks & Regards
Mastan Narravula
Mark as Answer", if it helped you or it might help others too.
Answer: 10
Hi Mastan,
No luck still I am getting same error.
Answer: 11
Hi,
I tried above one no luck still getting same issue.
Answer: 12
Hi Mastan,
objSFD.GetType().GetMethod("set_DefaultFileName") -> this part of the line is coming null. Any solution why?
Regards,
Santosh
Answer: 13
Hi Santosh,
I am following the solution Mastan Narra... provides, it works for me. So please check your code again. Below is my test code:
SaveFileDialog objSFD = new SaveFileDialog() { DefaultExt = "csv", Filter = "CSV Files (*.csv)|*.csv|Excel XML (*.xml)|*.xml|All files (*.*)|*.*", FilterIndex = 1 }; objSFD.GetType().GetMethod("set_DefaultFileName").Invoke(objSFD, new object[] { "untitled.txt" }); if (objSFD.ShowDialog() == true) { System.IO.Stream fileStream = objSFD.OpenFile(); System.IO.StreamWriter sw = new System.IO.StreamWriter(fileStream); sw.WriteLine("Writing some text in the file."); sw.Flush(); sw.Close(); } Please let me know if you have any question. If the issue still exists, please share your code or project (remove unrelated and sensitive code first) so that I can help you further.
Best Regards,
Answer: 14
hi santosh pls paste your code present in xaml and xaml.cs...
Answer: 15
Hi Mastan,
I am using silverlight 4 with MVVM pattern. Below is the code I tried in ViewModel.cs file:
public void ExportDataGrid(DataGrid dGrid, bool messagereqd) {
SaveFileDialog objSFD = new SaveFileDialog() {
DefaultExt = "csv",
Filter = "CSV Files (*.csv)|*.csv|Excel XML (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
string item = "testfile"
objSFD.GetType().GetMethod("set_DefaultFileName").Invoke(objSFD, new object[] { item });
}
I tried above code it is throwing Object reference not set to an instane.
objSFD.GetType().GetMethod("set_DefaultFileName") coming as Null.
Regards,
Santosh
Answer: 16
Hi Santosh,
Could you tell me which object reference not set to an instance? You can debug your project with the help of immediate window to examine which value is null? objSFD, objSFD.GetType(), or objSFD.GetType().GetMethod("set_DefaultFileName") ?
We need detail information of the exception. If you feel it is inconvenient to repeatedly paste code or error message, you can upload an simple demo that can reproduce your issue to SkyDrive and show me the download link, I will be very appreciated.
Best Regards,
Answer: 17
Hi Johnson,
I am developing this in silverlight 4 mvvm pattern. In view model I have done the above coding.
When break point hits and checked the quick watch window objSFD.GetType().GetMethod("set_DefaultFileName") coming as Null.
Regards,
Santosh
Answer: 18
Hi Santosh,
I am sure now where is your problem. It must be environment issue. It may be caused by different Silverlight version, or confilicts between different versions.
So I need your project code(removed unrelated and senstive code first), or you can upload an simple demo that can reproduce your issue to SkyDrive and show me the download link so that I can help you further.
Best Regards,
Answer: 19
Hi Johnson,
Please find the link for test application still I am getting same error in this application. Let me know if you can find any solution.
Regards,
Santosh
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog