你好,我有我正在使用下面的类来从sql服务器下载Excel文件,在WPF中使用Linq到Sql。我在使用该方法时遇到问题。写入二进制文件到.xlsx
public class Tables
{
public Guid Id { get; set; }
public byte[] Data { get; set; }
public string Notes{ get; set; }
}
物业
public ObservableCollection<Tables> Table
{
get
{
return mTables;
}
}
的方法(错误 - fileBytes没有出现在目前的情况下)
private void executeSaveAttachment(object parameter)
{
//Enables the apperance of a Dialog, where the user can specify where to save the file
SaveFileDialog textDialog = new SaveFileDialog();
//save the file in a bite array
// byte[] fileBytes = Table.ToList().ForEach(p => p.Data);
Table.ToList().ForEach(p =>
{
byte[] fileBytes = p.Data;
});
//Open dialog where the user determines where to save the file.
bool? result = textDialog.ShowDialog();
if (result == true)
{
using (Stream fs = (Stream)textDialog.OpenFile())
{
fs.Write(fileBytes, 0, fileBytes.Length);
fs.Close();
}
}
}
你'fileBytes'阵列是一个循环内初始化,所以它是不是在你的'下面if'语句的上下文中可用。 –