I have an embedded Resource File:
I need to open it as a Stream.
What I've tried (did not work, stream is null):
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("client_secret.json"))
Any ideas or suggestions?
Edit: What I'm doing with it:
using (var stream = assembly.GetManifestResourceStream("client_secret.json"))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
Embedded files are called as Embedded Resources and these files can be accessed at runtime using the Assembly class of the System. Reflection namespace. Any file within the project can be made into an embedded file. Advantages.
A . resx file contains a standard set of header information that describes the format of the resource entries, and specifies the versioning information for the XML code that parses the data. These files contain all the strings, labels, captions, and titles for all text in the three IBM Cognos Office components.
Open a . resx file in the XML (Text) editor. Press Ctrl+Alt+F or choose ReSharper | Windows | File Structure from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.
I solved this, I had to provide the full Namespace of the Resource:
using (var stream = assembly.GetManifestResourceStream("Project.Resources.client_secret.json"))
Right-Click your Project in Solution Explorer -> Add -> New Item -> Resources File
Then double-click on the created file (e.g. Resource1.resx), and then add your client_secret.json
to it. Now you can access to client_secret.json
content with blow code. Note that if you put a json file to resource, when get the client_secret you get a byte[] and must convert that to string
var foo= Encoding.UTF8.GetString(Resource1.client_secret);
But if only add .txt
file you can access to that file with:
var foo= Resource1.txtfile;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With