你可以稱之爲
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
,並檢查其嵌入的資源都可以訪問。然後你可以比較一下你正在通過的內容,看看你是否確實完成了你的預期。
string FileExtractTo = "C:\FILES";
DirectoryInfo dirInfo = new DirectoryInfo(FileExtractTo);
if (!dirInfo.Exists())
dirInfo.Create();
using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (Stream output = File.Create(FileExtractTo + "\template.dotx"))
{
CopyStream(input, output);
}
CopyStream方法:
public static void CopyStream(Stream input, Stream output)
{
// Insert null checking here for production
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
將這個罵人的字符串數組? System.Reflection.Assembly.GetExecutingAssembly()GetManifestResourceNames(); –
是的,這會以字符串[]的形式返回所有的資源,然後你可以調用GetManifestResourceStream(resourceName);獲取嵌入式資源的流。 –
看到我編輯的答案。希望這可以幫助! –