Silverlight导出数据

AngelicaA 2012-08-31

/// <summary>
        /// 导出数据
        /// </summary>
        private void btnExportData(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog();
            sf.DefaultExt = "txt";
            sf.Filter = "TXT Files (*.txt)|*.txt|All files (*.*)|*.*";
            sf.FilterIndex = 1;

            string data = "需要导出的数据信息";

            if (sf.ShowDialog() == true)
            {
                using (Stream stream = sf.OpenFile())
                {
                    //用utf8编码 
                    Byte[] fileContent = System.Text.UTF8Encoding.UTF8.GetBytes(data);
                    stream.Write(fileContent, 0, fileContent.Length);
                    stream.Close();
                }
            }
        }

相关推荐