2017-05-18 11 views
0

私のリソースフォルダに小さいPowerPoint個のファイルがあり、それらを開くことができます。私はResource.sendToPPTTempがタイプbyte[]であり、私はそれを文字列として必要とするファイルを開くために問題を抱えています。文字列としてリソースからファイルを開く方法はありますか?リソースファイルでPowerPointファイルを開く方法C#

var file = Resources.sendToPPTTemp; 
ppnt.Application ppntApplication = new ppnt.Application(); 
var _assembly = Assembly.GetExecutingAssembly(); 

var myppnt = ppntApplication.Presentations.Open(file.ToString()); 
ppntApplication.Visible = MsoTriState.msoTrue; 
+1

ありませんPowerpointはアプリケーションであり、ライブラリではありません。 * files *を開きます。バッファを一時ファイルに保存するなど、ファイルを提供する必要があります –

+0

なぜリソースにプレゼンテーションを保存したのですか?あなたは何をしようとしているのですか?アプリケーションでファイルを展開するだけではどうですか? –

+0

私は開く必要があるPowerPointファイルをいくつも持っており、すべての文字列パスを与えたくありませんでした。 –

答えて

0

あなたはOpen方法ではなく、バイナリ表現にファイルへのパスを与える必要があります。パスを取得してメソッドに渡すか、バイト[]でファイルを作成する必要があります。

私はむしろすべてのPPTでフォルダを作成し、そのフォルダへのパスをリソースファイルに保存したいと思います。そして、あなたは最初の方法を使用することができます

var di = new DirectoryInfo(Resources.PPTFolderPath); 
foreach(var file in di.GetFiles()) 
{ 
    var myppnt = ppntApplication.Presentations.Open(fi.FullName); 
    ppntApplication.Visible = MsoTriState.msoTrue; 
    [..] 
} 

をしかし、あなたが本当にリソースファイルにあなたのPPTを保存したい場合は、例えば、一時ファイルを使用して、このようにそれを行うことができます。

var tmpPath = Path.GetTempFileName(); 
try 
{ 
    File.WriteAllBytes(tmpPath, Resources.sendToPPTTemp); 

    var myppnt = ppntApplication.Presentations.Open(tmpPath); 
    ppntApplication.Visible = MsoTriState.msoTrue; 
    [..] 
} 
finally 
{ 
    // you have to delete your tmp file at the end!!! 
    // probably not the better way to do it because I guess the program does not block on Open. 
    // Better store the file path into a list and delete later. 
    var fi = new FileInfo(tmpPath); 
    fi.Delete(); 
} 
関連する問題