Request a topic or
contact an Arke consultant
404-812-3123
All posts tagged 'asp.net'

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Archive

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

The 5 minute MVC CMS

[Code at the bottom]

 

I had a client that needed a solution that could meet the following requirements:

  • Must be able to add and remove page from their website
  • Must be able to change the content of each of the pages
  • Users of the website would need to be able to have a logon state
  • The pages would need to show up in the navigation menu
  • Must be able to do all of this without using a developer, re-engineering their site, installing a CMS system, or taking more than 4 hours of custom development time. 

 

They also had the following merits:

  • Those who would change the content were proficient in Html, CSS, and basic web technology
  • All pages would have the same layout
  • Existing website written in ASP.NET MVC

 

In the end, the content managers had access to a "PartialPages" folder that set under the main site on the webserver.  The managers could add, remove, and edit these files.  They could also update the SiteMap.xml file for these pages, allowing for the navigation menu to update based on their changes. 

 

CODE:

 

 AreaRegistration - Routing:

 

context.MapRoute(
    "FiveMinuteCMS_Default",  // Route name
    "FiveMinuteCMS/{id}",      // URL with parameters
    new { controller = "FiveMinuteCMS", action = "Pages", id = UrlParameter.Optional }
);

 

 Controller:

 

public ActionResult Pages(string id)
{
    PagesModel model = new PagesModel();
    model.Page = System.IO.File.ReadAllText(HttpContext.Server.MapPath
        ("~/PartialPages/" + id + ".html"));       
    return View(model);
}

 

Model:

 

public class PagesModel
{
    public string Page { get; set; }
}

 

Pages View:

 

@model MySampleProject.Areas.FiveMinuteCMS.Models.PagesModel
@{
    // Any layout will do
    Layout = "~/Areas/FiveMinuteCMS/Views/Shared/_Content.cshtml";
}

@Html.Raw(Model.Page)

 

 

Sample Partial Page file:

 

<div id=”PartialContentBody”>               
    <span>Hello World</span>
</div>

 

For the site map and navigation, I used Maarten Balliauw's MvcSiteMapProvider


Tags: , ,
Categories: ASP.NET | MVC | CMS
Posted by Trenton Adams on Tuesday, August 20, 2013 4:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Serving PDF Reports from ASP.NET using SQL Reporting Services

I recently had to create a PDF on the server-side and deliver it to the client via ASP.NET.  There are several open source PDF APIs out there so the options are vast.  But I chose to leverage SQL Reporting Services instead of learning another API.  Plus, why program a report when you can design it using proven tools?

Using SQL Server Business Intelligence Development Studio, I created a reports project, developed a report called Report1, and deployed to SQL Reporting Services.  Here is a great article if you want help creating your first report.  Tutorial: Designing Your First Report in SQL Server Reporting Services.

Next, in my ASP.NET application, I added a Web Reference to http://server/Reportserver/reportservice.asmx and named it ReportsWS, which generates all the proxy classes needed to interface with Reporting Services from my code.  Now I just have to write a little bit of code to generate the report and deliver the PDF.  In the example below, you can also see how to pass parameters to the report named StartDate and EndDate.

Using rs As New ReportsWS.ReportingService()
    rs.Credentials = New System.Net.NetworkCredential(ConfigurationManager.AppSettings("RSUser"), ConfigurationManager.AppSettings("RSPassword"), ConfigurationManager.AppSettings("RSDomain"))
   
Dim sReportPath As String = ConfigurationManager.AppSettings("RSReportPath")
   
Dim sReportName As String = "Report1"

   
Dim ResultStream() As Byte

   
Dim StreamIdentifiers() As String = Nothing

   
Dim optionalParams(2) As ReportsWS.ParameterValue

   
Dim OptionalParam As String = Nothing

   
Dim optionalWarnings As ReportsWS.Warning() = Nothing
 
   
optionalParams(0) = New ReportsWS.ParameterValue

   
optionalParams(0).Name = "StartDate"

   
optionalParams(0).Value = "1/1/2007"

   
optionalParams(1) = New ReportsWS.ParameterValue

   
optionalParams(1).Name = "EndDate"

   
optionalParams(1).Value = "12/31/2007"

   
' Create and set the content type string
   
Dim contentType As String = "application/pdf"

   
ResultStream = rs.Render("/" & sReportPath & "/" & sReportName, "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", optionalParams, Nothing, Nothing, OptionalParam, OptionalParam, optionalParams, optionalWarnings, StreamIdentifiers)

   
Response.Clear()
   
Response.ContentType = "application/octet-stream"

   
Response.AddHeader("Content-Type", contentType)

   
Response.AddHeader("Content-Disposition", "attachment;filename=" & sReportName & ".pdf")
               
    Response.BinaryWrite(ResultStream)

   
Response.Flush()
               
   
Response.End()
           
End Using

 


Posted by Eric Stoll on Wednesday, January 2, 2008 9:39 AM
Permalink | Comments (0) | Post RSSRSS comment feed