2

こんにちは
、Silver-Light でファイルをアップロードしてみます。これを行うには、System.IO.File を使用してファイル バイトを読み取り、データをサービスに送信して、そのデータをファイル データとしてデータベースに挿入します。
(ブローコード)

        byte[] data;
        OpenFileDialog open = new OpenFileDialog();
        open.Filter = "Excel Files (*.xlsx)|*.xlsx";
        if (open.ShowDialog()==true)
        {
            open.File.OpenRead();
            data=System.IO.File.ReadAllBytes(open.File.FullName);
            //---- send for service ---Service.savefileindatabase(data);
        }

そのため、VS によってスローされる "ReadAllBytes" 例外を含む行でこのコードを使用すると、これは Exception Detail:
"File operation not allowed. Access to path '' is denied." になります。
(詳細については、選択したファイルがローカル ドライブにあった)

それで、私は何をしますか?

4

1 に答える 1

2

In Silverlight there are far more restrictions than in usual wpf programming. The files you might upload may be only in specific directories and some methods are not available like File.FullName. Only a manually selected file might be uploaded. Your starting code is OK. But in silverlight you do not have access to paths (only to the name).

There are some OpenText, OpenRead methods which allow you to get a stream from the selected file. From that point you'll be able to do what you want with the data coming from the stream.

if (open.ShowDialog())
{
    using (StreamReader reader = open.SelectedFile.OpenRead())
    {
       ...
    }
}
于 2010-06-24T05:24:22.337 に答える