Programmatically populate an ASP.net data table - asp.net

I'm trying to show a Sharepoint list on an ASP page that's running on a different server to the Sharepoint site. I originally tried using the Server Object Model, but with no success (see: Using Sharepoint GridViews on server without SharePoint installed)
So I have settled for using the Client Object Model instead. Now this allows me to pull data from Sharepoint, however, and please correct me if I'm wrong, there is no built in functionality that allows you to bind ASP.net data tables/grid views to Sharepoint objects. The ASP.net page runs on a server that does not have Sharepoint installed.
I would very much like to use ASP.net grid view objects, as they're very design friendly (visible in the GUI) and provide a whole host of functionality - sorting, paging, and so on. These objects need to consume ASP data sets afaik (I'm new to ASP.net development), so I've created a data set object, and a data table to source the data from.
These data tables are clearly designed to retreive data from SQL based sources, as the only options Visual Studio provides for populating them is from the various SQL platforms. However I was able to use the GUI to add the columns I wanted to the data table. These column names correspond to columns of metadata in the Sharepoint list I want to retreive from.
Now can anyone provide me with the steps - preferably with regard to best practice, that I need to go through in order to ensure that the grid view is populated with values when the user loads the page. I already know how to access the values via the Sharepoint web service, but I'm just not sure how to get them into the ASP data set.

By making use of the GetListItems method, I can have all the items of a particular list in the form of XML node. All I need is to convert this XML into data set. Here is how you can convert the XML node to DataSet. You can iterate through the xml nodes and create rows to your dataset as shown here.

Related

How to make dynamic webpages with ASP.NET that display different images pulled from a SQL database?

I am 100% new to ASP.NET and I've been working on this problem for a few weeks. I'm trying to have a very barebones website that when loaded will prompt the user for their dessert preference. If they like cakes, the website will display cake photos, if they like jelly, it will display jelly.
My first thought was to start with the SQL database. It has two tables, Jelly and Cakes, both have the same format for columns.
An integer for id, a varchar for name and a binarydata for storing the image.
Then I created the website on ASP.NET. I started by generating a ASP.NET Web App (MVC) in Microsoft Visual Studio. I tried to create a model class called Dessert that would create a dataset of either Jelly or Cakes dependent on what the user choose but I couldn't figure out how exactly to create that.
I went online and read some documentation and apparently ASP.NET can auto generate a SQL database based on your model? I toyed around with creating different models, trying to connect the model to my SQL database, auto-generating the SQL database with ASP.NET but I'll be honest and say, I haven't got a clue what I'm doing.
My initial feeling was to create a model, have some sort of starting page that asks the user their preference, the Dessert class gets made based on the user's preference and the webpages are dynamically displayed with whatever their preference was.
Any help on this would be appreciated. Even if it's just a link to a resource that can help me.
Thanks.
This involve many steps --
You create the db
Create Web Project
Add Option to connect with Database, you can use (Entity Framework, Plain ADO.NET, Dapper)
Create a db class to make methods that call db
Create model class to hold data returned from db
Create controller and call db class to get data and pass it to view
Create MVC view to show data and capture user intergation
For you use case I allready prepared some code and database, please look into this repo --
https://github.com/mataprasad/MyDesserts

SSRS dynamic report generation, pdf and subscriptions?

If this question is deemed inappropriate because it does not have a specific code question and is more "am I barking up the right tree," please advise me on a better venue.
If not, I'm a full stack .NET Web developer with no SSRS experience and my only knowledge comes from the last 3 sleepless nights. The app my team is working on requires end users to be able to create as many custom dashboards as they would like by creating instances of a dozen or so predefined widget types. Some widgets are as simple as a chart or table, and the user configures the widget to display a subset of possible fields selected from a larger set. We have a few widgets that are composites. The Web client is all angular and consumes a restful Web api.
There are two more requirements, that a reasonable facsimile of each widget can be downloaded as a PDF report upon request or at scheduled times. There are several solutions to this requirement, so I am not looking for alternate solutions. If SSRS would work, it would save us from having to build a scheduler and either find a way to leverage the existing angular templates or to create views based off of them, populate them and convert that to a pdf. What I am looking for is he'll in understanding how report generation best practices and how they interact witg .NET assemblies.
My specfic task is to investige if SSRS can create a report based on a composite widget and either download it as a PDF or schedule it as one, and if so create a POC based on a composite widget that contains 2 line graphs and a table. The PDF versions do not need to be displayed the same way as the UI where the graphs are on the same row and the table is below. I can show each graph on its' own as long as the display order is in reading order. ( left to right, then down to the next line)
An example case could be that the first graph shows the sales of x-boxes over the course of last year. The line graph next to it shows the number of new releases for the X-Box over the course of last year. The report in the table below shows the number of X-box accessories sold last year grouped by accessory type (controller, headset, etc,) and by month, ordered by the total sales amount per month.
The example above would take 3 queries. The queries are unique to that users specific instance of that widget on that specific dashboard. The user can group, choose sort columns and anything else that is applicable.
How these queries are created is not my task (at least not yet.) So there is an assumption that a magic query engine creates and stores these sql queries correctly in the database.
My target database is sql 2012 and its' reporting service. I'm disappointed it only supports the 2.0 clr.
OI have the rough outline of a plan, but given my lack of experience any help with this would be appreciated.
It appears I can use the Soap service for scheduling and management. That's straight forward.
The rest of my plan sounds pretty crazy. Any corrections, guidance and better suggestions would be welcome. Or maybe a different methodology. The report server is a big security hole, and if I can accomplish the requirements by only referencing the reporting names paces please point me in the right direction. If not, this is the process I have cobbled together after 3 days of research and a few msdn simple tutorials. Here goes:
To successfully create the report definition, I will need to reference every possible field in the entire superset available. It isn't clear yet if the superset for a table is the same as the superset for a graph , but for this POC I will assume they are. This way, I will only need a single stored procedure with an input parameter that identifies the correct query, which I will select and execute. The result set will be a small subset of the possible fields, but the stored procedure will return every field, with nulls for each row of the omitted fields so that the report knows about every field. Terrible. I will probably be returning 5 columns with data and 500 full of nulls. There has to be a better way. Thinking about the performance hit is making me queasy, but that was pretty easy. Now I have a deployable report. I have no idea how I would handle summaries. Would they be additional queries that I would just append to the result set? Maybe the magic query engine knows.
Now for some additional ugliness. I have to request the report url with a query string that identifies the correct query. I am guessing I can also set the scheduler up with the correct parameter. But man do I have issues. I could call the url using httpWebRequest for my download, but how exactly does the scheduler work? I would imagine it would create the report in a similar fashion, and I should be able to tell it in what format to render. But for the download I would be streaming html. How would I tell the report server to convert it to a pdf and then stream it as such? Can that be set in the reports definition before deploying it? It has no problem with the conversion when I play around on the report server. But at least I've found a way to secure the report server by accessing it through the Web api.
Then there is the issue of cleaning up the null columns. There are extension points, such as data processing extensions. I think these are almost analogous to a step in the Web page life cycle but not sure exactly or else they would be called events. I would need to find the right one so that I can remove the null data column or labels on a pie chart at null percent, if that doesn't break the report. And I need to do it while it is still rdl. And just maybe if I still haven't found a way, transform the rdl to a pdf and change the content type. It appears I can add .net assemblies at the extension points. But is any of this correct? I am thinking like a developer, not like a seasoned SSRS pro. I'm trying, but any help pushing me in the right direction would be greatly appreciated.
I had tried revising that question a dozen times before asking, and it still seems unintelligible. Maybe my own answer will make my own question clear, and hopefully save someone else having to go through what I did, or at least be a quick dive into SSRS from a developer standpoint.
Creating a typical SSRS report involves (quick 40,000 foot overview)
1. Creating your data connection
2. Creating a SQL query or Queries which can be parameterized.
3. Datasets that the query result will fill
4. Mapping Dataset columns to Report Items; charts, tables, etc.
Then you build the report and deploy it to your report server, where the report can be requested by url with any SQL parameters Values added as a querystring:
http://reportserver/reportfolder/myreport?param1=data
How this works is that an RDL file (Report Definition Language) which is just an XML document with a specific schema is generated. The RDL has two elements that were relevant to me, and . As the names infer, the first contains the queries and the latter contains the graphs, charts, tables, etc. in the report and the mappings to the columns in the dataset.
When the report is requested, it goes through a processing pipeline on the report server. By implementing Interfaces in the reporting services namespace, one could create .NET assemblies that could transform the RDL at various stages in the pipeline.
Reporting Services also has two reporting API's. One for managing reports, and another for rendering. There is also the reportserver control which is a .NET Webforms control which is pretty rich in functionality and could be used to create and render reports without even needing a report server instance. The report files the control could generate were RDLC files, with the C standing for client.
Armed with all of this knowledge, I found several solution paths, but all of them were not optimal for my purposes and I have moved on to a solution that did not involve reporting services or RDL at all. But these may be of use to someone else.
I could transform the RDL file as it went through the pipeline. Not very performant, as this involved writing to the actual physical file, and then removing the modifications after rendering. I was also using SQL Server 2012, which only supported the 2.0/3.5 framework.
Then there were the services. Using either service, I could retrieve an RDL template as a byte array from my application. I wasn't limited by the CLR version here. With the management server, I could modify the RDL and deploy that to the Report Server. I would only need to modify the RDL once, but given the number of files I would need and having to manage them on the remote server, creating file structures by client/user/Dashboard/ReportWidget looked pretty ugly.
Alternatively, I instead of deploying the RDL templates, why not just store them in the database in byte array format. When I needed a specific instance, I could fetch the RDL template, add my queries and mappings to the template and then pass them to the execution service which would then render them. I could then save the resulting RDL in the database. It would be much easier for me to manage there. But now the report server would be useless, I would need my own services for management and to create subscriptions and to mail them I would need a queue service and an SMTP mailer, removing all the extras I would get from the report server, need to write a ton of custom code, and still be bound by RDL. So I would be creating RDLM, RDL mess.
It was the wrong tool for the job, but it was an interesting exercise, I learned more about Reporting Services from every angle, and was paid for most of that time. Maybe a blog post would be a better venue, but then I would need to go into much greater detail.

Search through code for list of unique controls

Does anyone have a nice way to search through a WebForms web app to return the list of unique user controls used throughout the app (in .aspx and .ascx pages)? We've got 100+ pages and 150+ user controls. We are also using a few third party libraries and I want to see which controls we are using across the app. I'm not necessarily looking for a count of each unique control, just the unique items. For example: asp:Label, asp:MultiView, etc.
Thanks in advance.
I'm using NDepend when it comes to dependencies analysis and changes analysis. If you don't have licence trial version should allow you to use all features without restrictions.
Start from creation of the new project and add compiled assembly of your web application. It will automatically load all dependencies which you can browse with Class Browser. This will give you the basic understanding of what types (controls) are used by your web app.
Also you can narrow or extend your findings with Queries and Rules Edit (Ctrl+Alt+R). Run following query to get a list of used controls from System.Web.UI.WebControls:
from type in Assemblies.WithNameNotIn("WebApplication2").ChildTypes()
// depth is needed th find all controls that are used directly or indirectly
let depth = type.DepthOfIsUsedBy("WebApplication2".MatchAssembly())
// we are interested only in types from specific namespace, in this case "System.Web.UI.WebControls"
where type.ParentNamespace.Name == "System.Web.UI.WebControls"
where depth >= 0 orderby depth
select new { type, depth }
As you can see query result could be exported various formats (HTML, Excel, Text or Graph).
NDepend is very powerful tool mostly because of built in Code Query Language. It is based on the LINQ and you can start creating simple queries without any additional training or learning.

Available/default values for SSRS report custom parameters in ASP.net web application

I am planning to build part of an internal dashboard around SSRS reports. I'm using ASP.net (framework 4), SQL Server 2008 R2, IIS6 and have built all my reports already in Report Builder 3.0.
Now it comes to pulling the reports through from the report server to the dashboard using the ReportViewer control. What I would like to do is to hide the SSRS report parameters and provide them myself from code behind, because the SSRS parameter selection controls are ugly (Windows 95 ugly) and don't fit with the look and feel of the site. Also, I have different end-user reports that are in fact the same report with different parameter selections (and I don't want to show these selection controls).
The issue is that all of my reports are VERY heavily parameterised - the business users want reports that are as flexible as pivots (you can imagine the fun I had building these reports). As a result I use a large number of shared datasets to provide the default and available values for each parameter. Since I intend to present these parameters myself in my web application, I need to know:
What the parameters are for each report (name and type)
What the default values should be for each parameter
What the available options should be for each parameter
I am happy to store the names/types of each parameter in a database table, but there would be far too many values to store to do the same with parameters (plus the data is too dynamic). Can anyone think of a solution?
In fact, it is quite easy to retrieve the Default and Available parameter values used in the report:
Once you have set the report source, ServerReport.GetParameters() returns a collection of ReportParameterInfo which, for each parameter, provides the data type, default/available values ("Values"/"Valid Values" respectively, where "Valid Values" are value/label pairs) and other useful attributes like a list of other parameters that depend on it.
So, just save default/available parameters in the report (using Report Builder / Report Manager) and use this to retrieve them in your code behind.
IS this what you're looking for: http://msdn.microsoft.com/en-us/library/ms155391.aspx ? I'm not quite clear what your issue is from your post, what exactly do you need help with in doing what you're trying to do?

Key-Value pairs in ASP.NET - Clientside

I am very new to writing ASP.NET web apps..but i've been tasked with doing so. I have an extensive set of web services i've written that work with our backend databases. Up until now, i've written solely desktop apps using these web services. this is my first venture into web applications.
So far i've been doing quite well. But i've come to a point where i'm trying to minimize some postback delays.
I'm using a gridview to have users enter some data for a one-to-many relationship. One of the fields they select from a dropdown list. After selecting this list, i was doing a postback to get the corresponding key value and then displaying it but this took to long. Ideally, this should be instantaneous, so i was wondering what the best approach would be - clientside/javascript - to do a lookup on a list of name-value pairs?
From some preliminary web searching, it appears the two most popular approaches would be to use either a hidden field to store the lists, or to store it in a JSON object?
I'm looking for opinions on the best approach, and how specifically to store this list on the client side? From what i understand, using a hidden field could be the easiest.
Opinions?
I don't think you need to store it at all on the client side but rather do an async Ajax call to the server to retrieve the actual value. You should be able to accomplish this easily by putting the GridView and the displayed label controls into an UpdatePanel where the Trigger is defined as your dropdown list.

Resources