您的位置:首页 > 其它

读取嵌入到 Dll 文件中的资源文件

2006-07-19 12:36 507 查看
private static Hashtable _asmfiles;

public static byte[] LoadAssemblyFiles(string filename)
  {
   if (filename == null)
   {
    throw new ArgumentNullException("filename");
   }
   if (!filename.StartsWith("/"))
   {
    throw new ArgumentException("must starts with '/'", "filename");
   }
   filename = "/" + filename.Remove(0, 1).Replace('/', '.');
   if (Resx._asmfiles == null)
   {
    Hashtable afs = new Hashtable();
    foreach (string resname in typeof(Resx).Assembly.GetManifestResourceNames())
    {
     if (resname.StartsWith("UploadFileHelper.Uploader.File."))
     {
      byte[] buf;
      string fn = "/" + resname.Remove(0, "UploadFileHelper.Uploader.File.".Length);
      fn = fn.ToLower();
      using (Stream s = typeof(Resx).Assembly.GetManifestResourceStream(resname))
      {
       buf = new byte[s.Length];
       s.Read(buf, 0, buf.Length);
      }
      afs.Add(fn, buf);
     }
    }
    Resx._asmfiles = afs;
   }
   return (byte[]) Resx._asmfiles[filename.ToLower()];
  } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dll byte string stream null