How to create RDLC report and download pdf, excel, word files in Web API using .NET 5.0

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
excellent hello everyone in this video we are going to see how to integrate rdsl report in web apa okay so i have um shown a sample demo what we are going to uh create on this video okay so we are going to design one report template and we are going to download it in different formats okay so what i will provide here the report name and the format output which i required okay so it's successfully generated and i am able to download it okay yeah so this is the one and the second output format xls right if i press it and i will be getting this one xl5 the report okay so the third one will be the word file and that will be you know in the ms word talk one the same report you know i designed one report and i have downloaded in three different formats so i took this url and i can paste it over here and i can download it the format which i wanted pdf and it will be returning me the pdf file and if i put xls and it will be returning me the xls file and if i open and see the same output whatever the you know that i have provided and everything will be there so please watch this video till the end and subscribe to the channel in this video i have explained in detail how we can uh set up these things in web api and it will be really helpful when the real use case appears so it saves a lot of time a lot of time for uh our development you know development perspective okay thank you everyone please watch this video till then thank you [Music] hello everyone today we are going to create um in baby api how we can uh create pdf excel word all these documents as a downloadable file in one particular option using in dotnet core web api right so we have our own web api uh when we try to access the api that is that needs to provide uh an file like pdf or excel whatever so for that uh what we are going to have is uh there is one option called rdsl reports so i'm following this particular uh blog so where i can find in the internet and here the author of this blog has given some ideas and tips how we can integrate that in vba right so i'm going to follow uh this one and i'm going to make some tweaks then we will be you know uh we will be getting our output in the controller okay so for that what i do uh first of all i'm going to create a new uh web project asp.net core maybe project right as usual um web api okay then it is going to be a dotnet 5.0 uh web api so i think this is not a bpa project it's a web project yeah this is the one where we rdsl maybe okay so we have uh dotnet 5.0 and https and uh open api is integrated that's fine i'm creating the api now the empty project okay so once the created so the first system what we are going to do uh we are as usual we have one default api controller let's leave this as it is so the first part we are going to create some you know some basic files and uh packages that we are going to install it right so first what i will do uh i'm going to install the necessary packages so i will so what i will do i will open nougat package manager and from there i'm going to install asb.net reporting so this nougat package will help us to create report files right so i'm installing this one and providing all the necessary privileges to continue okay then report viewer code dotnet code okay this is also one of the tool uh it will help us to view in the visual studio right so this is this is not an official nougat package from microsoft but still they are collaborating it maybe in future we will be getting this report viewer okay so that's fine we will we will have that so the next next one is system.drawing.com so this is important and it will help us in the background and then the text encoding dot code pages so these four are the main packages that we are going to use it in this particular project so we can see it here all these are installed in the project asp.net core dot reporting report viewer and then draw drawing dot common and encoding these four are important then uh we will proceed with this okay so uh the basics things are ready right so the next one is we we are going to create the report file for example first of all i am going to add a new folder for example in our project we will be having multiple reports right so in that case each report file contained a separate report for that we can create this report file by using uh you know by using our form windows form applications and we can get this two files in uh you know two files from internet so i got this file from the internet and the same article i found it and i'm reusing the same to [Music] start with okay after starting we can modify the file as per our requirement only the designing part is there that part i will explain later in this video right so what i will do i'll just copy these two two files and paste it here in the project and i will mark this two file the first and basic step and i right click this file and go to the properties and in the advanced option i have to mention the content and we need to copy always this is the very very important step that we have to provide otherwise it will not copy uh during the project compilation and project you know project build the creation time so this is important right and the next step is we can see here there is one if i double click on it usually we will be having like a xml file so i have installed on a additional extension tool in studio uh go to the visual studio then you can find it in the online microsoft or dsl report designer so i already installed in my local uh pc you can install it by searching or diesel report designer uh from that you can install this one and configure it in your excel uh sorry visual studio uh 2019 or uh whatever the versions that you are uh using if it is compatible with right so uh once you have configured this one this is the report user report that we are going to uh download which i took from the internet so thanks for author so okay so what i will do um the basic setup is ready now and the next stage will be we have to create our own report service and then the report controller these are the two major things which we have we have to follow it okay so for that what i will do i just go and create one more folder called services right in that service i am going to add a class called report service so this is nothing but our you know uh normal service that we we write every day right so we uh for the uh i'm going to create one interface on the same name the report service okay and i am going to return a byte array byte array generate asynchronous okay what i'm going to provide is a report name report name and uh report type that means it's excel or pdf or whatever it is report type these two or i'm going to uh do and i am going to provide the implementation of this so we are going to implement the actual report generation logic right so first of all we have to take this report file okay whichever the report we are going to use that we have to uh okay what we are do what we are going to do now first uh step we are going to identify this baby apa this web api is important right so once we build the solution we will be getting you know once we the solution we will be getting rdsl report uh rdsl web api so this path right this is the output where we will be having all our uh uh you know all our build files and release files everything right so in the deeper dot number five we will be having everything here and we we can find it our report files over here right so this is the one so first we have to find this dll this is the output dll this part we have to uh you know identify and we have to implement from there we need to take the rdsl file then we will need to pass our values right so to do that directory path and we are going to take it from the assembly assembly dot get executing assembly so this is coming from a system reflection and we are getting the location so we have to provide this name okay this is the one we are going to take it okay this is fine okay we are we took that file directory pass the second second stage will be string this rdsl file path with the name so i just have this one by default okay i'm providing the file path the first one what i'm doing is like you know i'm just converting the you know comparing uh the string i'm providing this file path and the report path the report file is this one user details right so it will fetch this file fetch this file and hold it in the rdsr file right okay and then now i need to create a instance of the system dot uh code pages so this is we we have to do it so for that what we can do like encoding ring dot register provider code pages dot instance so this is the one we can provide our more pages provided okay so the instant has been created and we will set the uh encoding format right get encoding as you know utf hyphen 8 or whatever the format we are using it right and then we have to load the local report file you put new locker report so this local report is nothing but this rdsl file path so we have this file and we are loading uh here in the asp.net report okay so which means now we have loaded this particular file and what is the next next one so we have loaded right we can we can go and see in the user we have first name last name email and phone for this we have to create one model so each model and a data source we have to provide based on that we can you know bind it for uh for our general use case uh we we have a model separate view model or model we will use based on that we can uh you know we can define it so what we can say uh from our use case we have one use my it's a duo right property first name and last name and we can rename the properties like your last name and email phone okay so we have created our dto so now what we can provide we have to supply uh this ddo right so we need to create uh proper you know data for report generally in our uh real-time use case it will be like you know we are calling a database with certain parameters and fetch the result and bind it here so here for the you know for for the simplicity i am just providing static values user data okay so i'm just giving [Music] the reference so that it will be right so now uh what i will do i'll just add user one new first name and the last name something like we can whatever we have right and the mobile number the phone number which now we use some random number that i am providing right so the same way we can provide it for multiple uh rows right so we can rename it that's fine so we have prepared the data right okay i put one this data and in the user list service dot add okay and what we have to do is this one we have to add we have a report right report dot and data source so this is our data source so in this data source users and the users should be the user list and now we have to create one you know dictionary object which is a string comma that means we are going to pass some key pair values like [Music] parameters so after this we have to you know execute this one okay so here we can notice that render type right and the parameter we have to pass this to uh and the page index all these values we have to pass it okay first of all we need to create the render type so render type is nothing but pdf or excel or word that one okay so for that what we will do we will create a separate file so there are three properties we are going to use it and we will pass it this one okay so uh render type we have to use it right so what they are asking is render time so we will create a new function and this is going to return render time okay get render type so we are going to provide a render type so we this one report time right this report type we are going to send and we are going to return the same one so the value will be rendered type by default we will set it as rendertype.pdf so we can see these many types we can you know generate the reports so for our use case we will be using pdf excel and word this three we are going to have it in our demo right so for that what i will do i will make a switch yes and you can make it a default then yes yeah for these two types i'm going to set a render type render type dot pdf okay and for other cases xls xls this is for excel for excel we will be having excel and word will be having word or we can make it work so we need to have a break okay these three things and i'm going to return it so okay i'm just shorting it so to identify this is better okay so this i'm going to send it from here it will return us this type based on that it will you know it will be executed once we get this result okay we need to return return dot mainstream that's it so this mainstream contains the byte array that is what we are going to return it in our uh file right okay so for now what we have done is like we just get all the values and we you know we loaded the report and we prepared the data and then we executed the report and get that so what is this this user data right in the report file we can see the data sources you know data set this is the one right from here it will match with these values so this user did you properties and this data set user data set users properties should be matched so that it will be you know it will be taken and displayed here so how we can change this one we can can click we can double click this one and you know we can change it as per our requirement right so uh if you want we can add it more you know more um more properties as we like okay that's it so this is uh this is fine and we we need to add it in the startup startup file so that dot add scope oh right okay so we provided that dependency injection so so that it will be so so everything is ready now that's good the main part we have to create our controller that is very important right so what i will do i am going to create a report controller now i am just adding the controller api and empty controller and i'm going to name it report so i've just created a empty container and i'm going to provide that report service right and we are going to have a report service and we'll set it as this right so the report service is ready now so the next part you know we need to create a one http method we get method where the report name right report name and the report type these two we are going to get it so this we can modify it as per our you know as per our need but the core is this one so it's going to be written now on action result and we are going to get a string name and then another one is report type right so we are going to return f file direct file we are going to return it because it's going to be output stream right so we are going to return a file which contains of the same style okay this one this file contains two things one is byte array and the content type right so the byte array is nothing but our report service right byte stream okay report service dot generate so we are going to get it so we will just pass these two values and then it will we will be receiving the report file right this byte array we will get it and i'm just passing this one then the content type okay this content type is nothing but the output you know output format media type name names dot application okay so this library we can you know use it from the mime type so this is the one and the output file name right so what we can do is we need to format the file name right the file name we need to provide otherwise some random you know random value will be there so for that what i will do i'll just make it as a get report name and i am going to pass these two values so based on the type so what i will do i will just use the same one where we have a return right here xls word okay the same i'm going to use it but instead of this one i'm just providing this dot pdf that's it output file name so this is going to basting a straightforward string that we are going to return it okay so i'm just giving uh right so for excel excel s then for a word it's going to be doc okay these three things and we are getting it and i'm going to you know provide it here the two values i'm providing here okay so it's pretty simple and we have you know we are straightforwardly we have used it okay so i'm just rebuilding the application so it's got success and i'm going to run the project so the project is running now so i wear with the ap endpoint is there so report name report name is nothing but this one user details right i'm going to provide user details what what is the format i'm going to get pdf so if i press it okay so yeah i got one sample uh you know fine and if i click on it it will download the user details file so it has all the values and it's printing successfully so for our case uh it is fine right so for you know for pdf it is working now and [Music] for the excel excel let's we need to provide and that also let's wait for the result and yes for excel also it is generating okay so with the same output or whatever the value which we have provided so in one thing it is uh you know it is created and then for word we need to provide a word right we have to mention what word right so i'm just mentioning the word and yeah now it's showing up some error and error occurred during local report processing i finished research for you know some word render picture descriptor you know this this is not nothing but the binary format serialization and dc releases is disabled within this application so what we are going to do we need to enable this particular you know binary format serialization okay how we will enable it for this case we need to go to the top and [Music] in that we will be you know this is not safe but still we have option called enable unsafe binary formatter serialization this is the error which we received right binary format serialization is not enabled so we will be you know enabling here and we will set that option true and it will be you know it will generate the uh file right okay let's run that api okay so we will be supplying the values user details and the output will be word and we will be getting our word document yes so it is available in the world so we can uh define uh whatever the you know uh whatever the output format we wanted as like the design whatever the design we wanted and we can you know get it in the different uh tools okay i hope uh this tutorial will be helpful for you you know to [Music] you know as a base from this base you can use it for your uh use case whatever the you know whatever the point uh whatever the feature that you want to develop it in the report you can do so okay so it's up to our limitation so the basic setup is this one okay this uh this one and this part okay so this is enough from this you can customize this report and design this report as like you want okay so yeah so in this tutorial we have learned how to integrate rdsl report in web api and to get the report okay and thank you thank you uh for that great article provided by the person and i hope this video will be helpful for you and and i request everyone to subscribe the channel and watch the video till the end and you know to support if you like these videos and channel right that will keep motivating me to do more videos thank you everyone [Music] you
Info
Channel: JAGAN DIGITECH
Views: 21,821
Rating: undefined out of 5
Keywords: .net5, asp.net core 3.1, automapper, code first approach, .net5 in tamil, web api in tamil, asp.net web api in tamil, .net core web api in tamil, flutter, dart, flutter web, flutter developer, flutter sdk, flutter backend, flutter in tamil, dart in tamil, flutter app in tamil, flutter ui design in tamil, jantechsdk, best practices
Id: 43LsblIA-v4
Channel Id: undefined
Length: 50min 20sec (3020 seconds)
Published: Fri Aug 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.