How to read embedded resource text file

前端 未结 22 2361
悲&欢浪女
悲&欢浪女 2020-11-21 06:03

How do I read an embedded resource (text file) using StreamReader and return it as a string? My current script uses a Windows form and textbox that allows the

22条回答
  •  花落未央
    2020-11-21 06:35

    You can add a file as a resource using two separate methods.

    The C# code required to access the file is different, depending on the method used to add the file in the first place.

    Method 1: Add existing file, set property to Embedded Resource

    Add the file to your project, then set the type to Embedded Resource.

    NOTE: If you add the file using this method, you can use GetManifestResourceStream to access it (see answer from @dtb).

    enter image description here

    Method 2: Add file to Resources.resx

    Open up the Resources.resx file, use the dropdown box to add the file, set Access Modifier to public.

    NOTE: If you add the file using this method, you can use Properties.Resources to access it (see answer from @Night Walker).

    enter image description here

提交回复
热议问题