国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

[C#]ExtractEmbeddedResourceToFile

2019-11-14 16:27:50
字體:
供稿:網(wǎng)友

關(guān)鍵代碼:

        /// <summary>        /// 將嵌入的資源寫入到本地        /// </summary>        /// <param name="resourceName">嵌入的資源名稱</param>        /// <param name="filename">寫入本地的路徑</param>        /// <returns>是否成功</returns>        public static bool ExtractEmbeddedResourceToFile(string resourceName, string filename)        {            bool _result = false;            try            {                Assembly _curCall = Assembly.GetCallingAssembly();                string _curCallAssemblyName = _curCall.GetName(false).Name;                resourceName = string.Format("{0}.{1}", _curCallAssemblyName, resourceName);                using (Stream stream = _curCall.GetManifestResourceStream(resourceName))                {                    if (stream != null)                    {                        using (FileStream fs = new FileStream(filename, FileMode.Create))                        {                            byte[] _byte = new byte[stream.Length];                            stream.Read(_byte, 0, _byte.Length);                            fs.Write(_byte, 0, _byte.Length);                            _result = true;                        }                    }                }            }            catch (Exception ex)            {                _result = false;                Debug.WriteLine(string.Format("ExtractEmbeddedResourceToFile Exception:{0}", ex.Message));            }            return _result;        }

測試代碼:

1.將文件設(shè)置成嵌入成資源

image

2.編寫代碼:

CSharpToolV2.ExtractEmbeddedResourceToFile("cat.jpg", @"C:/cat.jpg");

希望有所幫助!


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 黑河市| 榆林市| 达拉特旗| 上饶县| 金寨县| 曲水县| 屯留县| 抚顺市| 东乌珠穆沁旗| 连平县| 吉安县| 烟台市| 克拉玛依市| 元氏县| 宜丰县| 神木县| 融水| 瑞金市| 专栏| 新源县| 龙游县| 阿勒泰市| 东莞市| 东阳市| 黎城县| 漳州市| 睢宁县| 北宁市| 卢龙县| 九江市| 三河市| 乌拉特后旗| 平阳县| 景洪市| 大石桥市| 曲阜市| 治多县| 普兰县| 长沙市| 天门市| 巫溪县|