Net.Core 3.1 + Embedded Resource

Peter Forstmeier 21 Reputation points
2021-02-04T15:42:39.107+00:00

Hi alltogheter,
this is my *.csproj

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>ErpDach.Modules.Main</RootNamespace>
<UseWPF>true</UseWPF>
<AssemblyName>ErpDach.Modules.Projects</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>......\Bin\Debug\Modules\</OutputPath>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<None Remove="Reports\ProjectHeaderRDLC.rdlc" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Reports\ProjectHeaderRDLC.rdlc">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="9.4.0" />
<PackageReference Include="Prism.Wpf" Version="7.2.0.1422" />
<PackageReference Include="Syncfusion.SfGrid.WPF" Version="18.3.0.52" />
<PackageReference Include="Syncfusion.Tools.WPF" Version="18.3.0.52" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="....\Backend\ErpDach.Repository\ErpDach.Repository.csproj" />
<ProjectReference Include="....\Base\ErpDach.Base\ErpDach.Base.csproj" />
</ItemGroup>
</Project>
How do i acceess the Resource 'ProjectHeaderRDLC.rdlc' in Code?

var resourceName = 'ErpDach.Modules.Projects.Reports.ProjectHeaderRDLC.rdlc'

var assembly = Assembly.GetExecutingAssembly();
var x = assembly.GetManifestResourceStream(resourceName);

is nor working. I have no idea what i'm making wrong
Thanks
Peter

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,831 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,408 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,201 Reputation points
    2021-02-04T16:22:58.03+00:00

    Try the following, rather than a resource, add the report files under a folder e.g. Reports.

    Add this class, change the namespace name.

    using System;  
    using System.IO;  
      
    namespace TAPSNG.Helpers  
    {  
        public class GeneralHelper  
        {  
            public static string AssemblyDirectory  
            {  
                get  
                {  
                    string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;  
                    UriBuilder uri = new UriBuilder(codeBase);  
                    string path = Uri.UnescapeDataString(uri.Path);  
                    return Path.GetDirectoryName(path);  
                }  
            }  
        }  
    }  
      
    

    Sample usage, change the path and report name

    GeneralHelper.AssemblyDirectory + "\\Reports\\Form132Quarter1.rdlc";  
    

    64133-reports.png


0 additional answers

Sort by: Most helpful