Reporting Service generate to pdf error

by N-Technologies 9 August 2007 13:49

I was trying to generate a reporting service rpt to pdf-format.
The report got generated but when i tried to open it , this message was shown
"There was an error opening this document. The file is damaged and could not be repaired."

private void renderpdf()
{
string historyID = null;
string deviceInfo = null;
string format = "PDF";
Byte[] results;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
Rse2005.Warning[] warnings = null;
string[] streamIDs = null;

Rse2005.ReportExecutionService rsExec = new Rse2005.ReportExecutionService();
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
//rsExec.Credentials = new NetworkCredential(username, password, domain);

Rse2005.ExecutionInfo ei = rsExec.LoadReport("/PdfReport/pdf01", historyID);
Rse2005.ParameterValue[] rptParameters = new Rse2005.ParameterValue[1];

rptParameters[0] = new Rse2005.ParameterValue();
rptParameters[0].Name = "ReportMemo";
rptParameters[0].Value = "";

//render the PDF
rsExec.SetExecutionParameters(rptParameters, "nl-be");
results = rsExec.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

!!
Response.AddHeader("content-disposition", "attachment; filename=pdf01.pdf");
Response.OutputStream.Write(results, 0, results.Length);
Response.End();
>>
}

Solution !!
replace the lines in red with these...

Response.Clear();
Response.ContentType = mimeType;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer = false;

Response.AddHeader("Content-Disposition",
string.Format("{0};FileName=\"{1}\"", "attachment","pdf01.pdf"));

Response.OutputStream.Write(results, 0, results.Length);
Response.End();

>>>>
Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

N-Technologies

How to host an asmx in a windows service without using IIS ?

by N-Technologies 19 April 2007 20:29

For a project I'm currently working on, we need a service that send on regular base a signal to a certain system, this service can't be hosted in IIS and we need to use a windows service because the Windows Service can continuously send that signal. This service uses an httplistener to receive the soap messages from clients and parses the incoming SOAP to get the data. This simulates the IIS so soap calls can be send through HTTP, clients are not aware of the fact that they are not talking to IIS. This concept allows keeping sending the heartbeats while processing the soaprequest.

Read more in the article of Sven Cipido.

Written by Sven Cipido


Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

N-Technologies

SQL Server Reporting Services: Create and Call a Custom Assembly

by Admin 26 March 2007 21:35

 

In one of my previous articles I explained how to use embedded code in SQL Server Reporting Services. The possibility to add embedded code to a report, is a very powerfull feature to add some custom functionality to your report.
But sometimes it might be necessary to add some custom functionality that is too complicated for embedded code to handle efficiently, or you need to access the same function from multiple reports, or you would like to write you code in C#...
In one of these cases you should develop a custom assembly to call from your report.

Let’s start with a simple example and develop a function PercentageToColor() to return a color based on a numeric value representing a percentage.

namespace MyAssembly

{

    public class Colors

    {

        public string PercentageToColor(double percentage)

        {

            string returnValue = string.Empty;

 

            if (percentage < 20)

            {

                returnValue = "red";

            }

            else if (percentage < 80)

            {

                returnValue = "blue";

            }

            else

            {

                returnValue = "green";

            }

 

            return returnValue;

        }

    }

}

Once you’ve compiled your class you need to copy the resulting assembly to the directory in which it is accessible from within your report:

·         To use it in the report designer, you need to copy it to:
 
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies

·         To make it available for reports that have been deployed to the report server, you need to copy it to:
 C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin

 

 

Before you can access your custom assembly you have to reference the assembly: Open the report properties (Menu: Report – Report Properties) and select the References tab.

Browse to your assembly and define a Class Name and an Instance Name. (The Class Name and the Instance Name or only for non-static methods). Make sure to prefix your class name with the assembly name.

Now you can call the methods in your assembly from your report, using an expression:

·         To call a static method: =<AssemblyName>.<ClassName>.<StaticMethodName>

·         To call an instance method: =Code.<InstanceName>.<PublicMethodName>

So in our example this would be: =Code.TestColor.PercentageToColor(Fields!Percentage.Value)

 That's it! You've just created and called a custom assembly from your report...

 

 In one of my future articles I will explain how to pass parameters to the class constructor and I will also tell something about SSRS and .Net Permissions...

 

 

Davy Knuysen

 


Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , ,

N-Technologies

Embedded Code in SQL Server Reporting Services

by Admin 10 January 2007 00:26

 

Sometimes it might be necessary to use the same expression on different places throughout a report. You can of course just copy and paste the expression every time you need it, but if you'll ever need to change this expression, you will have to change it for every field you’re using it for. Therefore it’s good practice to write this expression just once and refer to it where necessary. This can be done by implementing embedded code, that can be entered through the report’s property dialog on the Code tab.

 

(Click “Report”, “Report Properties” and select the Code tab)

 

 

                

 

Assume you have some calculated percentage fields and you need to set the background color depending on it’s value:

-          when the value is less then 20% : background must be red

-          when the value is between 20 and 80%:  background must be orange

-          when the value is greater then 80%: background must be green

 

Add the following function to the custom code textbox:

Function GetColor(ByVal percentage As Double) As String

        Dim returnValue As String

 

        Select Case percentage

            Case Is < 20

                returnValue = "red"

            Case Is < 80

                returnValue = "orange"

            Case Is > 80

                returnValue = "green"

        End Select

 

        Return returnValue

End Function

 

Now you can access this function as a member of the class called “Code”:

=Code.GetColor(Fields!CalculatedPercentage.Value)

 

The Embedded Code Window is a very handy tool to quickly add some easy functions to your report.

But at this time, Embedded Code only supports Visual Basic and the Embedded Code Window is nothing more then a large textbox, without Intellisense or any debugging info.

Embedded Code can also only be reached from within the same report.  

Therefore if you want multiple reports to access the same code, or you would like to write your code in C#,  or do some really advanced things, you should consider accessing a .NET assembly from the embedded code, which I will explain in one of my future articles…

 

 

Davy Knuysen 

>
Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

N-Technologies

ASP.NET: View State and Dynamically Added Controls

by Admin 2 November 2006 23:39

I recently struggled with a view state related bug that was very hard to solve. Almost the whole page was build dynamically. The controls were nested within each other and the sequence and the number of controls could be different between every postback. Solving this bug, I came across some interesting articles about dynamically added controls and how to manage their view state. I just wanted to share some important things to keep in mind while adding controls dynamically…

 

·         When adding controls dynamically to an ASP.NET page, you need to rebuild these controls on every PostBack. If you need to persist their view state, you should be adding these controls before the view state stage, because the controls must exist within the page’s control hierarchy before the view state is loaded. For this reason it’s best to add these controls in the page class’s Init event.

 

·         Another important thing is to use the same ID for the control between postbacks.

 

private void Page_Init(object sender, EventArgs e)

{

            CreateControls();

}

 

private void CreateControls()

{

            TextBox tb = new TextBox();

            tb.ID = PreviousID;

 

            Page.Controls.Add(tb);

}

 

·         It’s also very important to remember that the parent control, where you add the child control to, also contains the view state of its children. So when adding a new control, be sure you add the control to the end of the parent’s control collection. The reason is because the parent's view state specifies the view state of its children by index.

 

 

For more info about view state, there’s a very interesting article on MSDN: Understanding ASP.NET View State

 

 

 

Davy Knuysen


Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

N-Technologies

WPF: getting started

by N-Technologies 2 August 2006 10:14

People have been asking me questions about WPF, mostly how to get started.
Since WPF is still somewhat obscure, in this article I’m going to try to make things a little more clear to get you on your way using WPF.

As you might or might not know, WPF is part of .net 3.0, formerly known as WinFX. Other components included in .net 3.0 are WCF (Windows Communication Foundation), WF (Windows Workflow Foundation) and CardSpace (formerly InfoCard).

For starters, you need an operating system supporting WPF. This can be:
-Windows XP SP2
-Windows 2003
-Windows Vista

I do recommend running .net 3.0 in a virtual pc environment! Since a lot of CTP’s, beta’s and RC’s are coming our way, it’s easier to just create a VPC with Windows XP or 2003 , and install .net 3.0! Since Virtual PC is free anyhow, I don’t see a reason why not doing it this way!
Uninstalling beta software can be a real pain, so why compromise your precious production environment!?
(For Virtual PC go here)

On both XP and 2003, you need to install the runtime, to be able to run WPF applications. This can be a web-install (of around 2.5 MB, and then the rest is downloaded) or you might as well download the whole package.

Now, there are some issues with the latest CTP of July… This latest release does not come with the Visual Studio 2005 extensions, required to build your WPF applications in VS.
Therefore, if you want to start developing (or better, start playing around…), I suggest you stick to the June CTP, which has full support for all the tools.

So, if you want to develop within Visual Studio, follow the next steps. If not, skip this section.
The June CTP runtime can be downloaded here.

To start developing, you might want to install the SDK. It’s a big download of around 1.1GB. It comes with lots of samples and tools, like XAMLPad. The SDK can be downloaded here.

The SDK is however not required when you intend to develop in Visual Studio! For VS, Microsoft has released some extensions and templates, which will make your WPF-life a lot easier! If you don’t have Visual Studio, you can use one of the free Express editions.
For the download, go here.

We’re almost done!
Microsoft is also preparing a set of designer tools for WPF, the Expression suite.
The Interactive Designer outputs XAML code, which can be used to enhance the layout of your applications, without even knowing XAML!
For the Interactive Designer, go here.
The Graphic Designer allows you to create images and export these as XAML code to be included in your WPF projects.
This can be downloaded here.

That’s it! Now, you are ready to start!

If you want the latest release, and don’t care for the Visual Studio Extensions, go for the July CTP, which was released July 18th.

The runtime can be downloaded here.
And the SDK is found right here.

I did find some work around to get this latest CTP working with Orcas, but since I didn’t try it myself, I cannot guarantee that it will work.
The “fix” goes as follows:

Instal Orcas in VS using the misexec override: msiexec /i vsextwfx.msi WRC_INSTALLED_OVERRIDE=1

The override bypasses the installation version checking so you can install the extensions.

After this you have July CTP installed and Orcas from the previous version. This works just fine.

To solve your problem with the Orcas designer trying to open:

Right click on a .xaml file in your solution and choose "open with...". Choose "xml Editor" and click on "Set as default". Now all .xaml files will open with the xml editor instead of trying to open the unfinished Orcas designer.

In a next article, I’ll post some interesting resources to get you building WPF applications in no time!


Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

N-Technologies

Microsoft.Office.Interop.Excel not found

by N-Technologies 11 July 2006 09:53

I was today a small project to write Excel files from .net. As you might (or might not...) know, you have to reference the Office DLL's for that.
I opened the project I made on a work-pc on my laptop, and all of a sudden, it didn't compile anymore.

The Microsoft.Office.Interop.Excel was missing. However, Office (and thus Excel) 2003 is installed on my system. After some googling (it's an official word know, so let's use it ;-) ), I found out that I probably installed Office 2003 before I installed the .net framework 1.1 (shame on me...). If you install in this order, the PIA's are not installed with a typical install.

The solution was simply run the Office setup, and install the .net Programmability Support. Problem solved... Another thing to remember when installing a new development PC!

 

gill cleeren


Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

N-Technologies

The TypeForwardedToAttribute, a new feature of C# 2.0

by N-Technologies 28 June 2006 22:55

With the TypeForwardedToAttribute it's possible to move a class from an assembly to another assembly without the need to rebuild the application who needs it.

Consider this scenario :

1. App1 references Lib1 and uses a class in this Library.
2. App1 and Lib1 are deployed and run OK.
3. Later Lib2 is created which must contain that class.
4. The class is moved from Lib1 to Lib2.
5. A reference is made from Lib1 to Lib2.
6. Lib1 gets a TypeForwardedToAttribute.
7. Both Lib1 and Lib2 are redeployed. App1 is not touched.
8. App1 still looks in Lib1 for the class, but Lib1 forwards the instantiation to Lib2.

Here's some code showing the implementation :

The initial code for Lib1

 namespace TestOnTypeForwardedToAttribute
 {
 
      public class TheClass
      {
          public void Test()
          {
               Console.WriteLine("In LIB 1");
          }
      }
 }

The code for App1

 namespace TestOnTypeForwardedToAttribute
 {
      class Program
      {
          static void Main(string[] args)
          {

               TestOnTypeForwardedToAttribute.TheClass oX = 
                 
new TestOnTypeForwardedToAttribute.TheClass();


               oX.Test();
               Console.ReadLine();

          }
      }
 }

Running this application shows us In LIB 1 as expected.

Now we create Lib2, give it the same rootnamespace as Lib1 and copy the class in it changing the string written to demonstrate that the second library is used.

Code for Lib2

 namespace TestOnTypeForwardedToAttribute
 {
 
      public class TheClass
      {
          public void Test()
          {
               Console.WriteLine("In LIB 2");
          }
      }
 }

We can delete the file containing the class from Lib1 and we add a reference from Lib1 to Lib2.

Lastly we add the TypeForwardedToAttribute in the AssemblyInfo.cs of Lib1


        [assembly: System.Runtime.CompilerServices.TypeForwardedTo
               
(typeof(TestOnTypeForwardedToAttribute.TheClass))]


Now we build Lib1 and Lib2 and deploy them both to the location of the application.

Run the Application again and notice that the output is now In LIB 2

Summary

By using the TypeForwardedTo attribute Lib1 knows that he's got to forward the calls to the not existing class to another library. So the application gets the class from Lib2 instead of Lib1. This is done transparent for the calling application. The caller doesn't know better that he's getting the class from Lib1. App1 does not need a reference to Lib2, neither must it be redeployed.

Great, we can move our classes to whatever assembly we want without the need for updating the calling application.

Kurt CLAEYS


Click here to see the original post

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

N-Technologies