Wednesday, December 3, 2008

Invoking "Save as PDF" method of Report Viewer

UserEntryFormEntity oEnt= new UserEntryFormEntity();
List oEntity = new List();

oEnt = GetReportData(JoinersId); // Method Which returns a List of Data
oEntity.Add(oEnt);

Microsoft.Reporting.WebForms.LocalReport localReport = new Microsoft.Reporting.WebForms.LocalReport();
localReport.ReportPath = Server.MapPath("~/DocumentTemplates/UserEntryForm.rdlc");

Microsoft.Reporting.WebForms.ReportDataSource oDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("UserEntryFormEntity", oEntity);
localReport.DataSources.Add(oDataSource);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo = "" + " PDF" + " 8.5in" + " 11in" + " 0.5in" + " 1in" + " 1in" + " 0.5in" + "";
Microsoft.Reporting.WebForms.Warning[] warnings;
//Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
//Clear the response stream and write the bytes to the outputstream
//Set content-disposition to "attachment" so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();

Friday, October 31, 2008

Best Practices for Writing HTML in Web Parts?

Something that's as puzzling as the Cadbury secret (and we all know that us programmers figured that out long ago) is just what's the best way to write out HTML in Web Parts? So call me masochistic but I write Web Parts with code. Yes, it's ugly. Yes, it's painful. Yes, you could use something cool like SmartPart or load the controls yourself (but that brings on a host of other issues like Code Access Security so we won't go into that).

For those of us that hold true to the "old fashioned" way, what's the best way to write all that code out? Consider these two approaches that writes out a label and control in a row for a form:

private void RenderRow(HtmlTextWriter output, Label label, WebControl control)

{

output.Write("");

label.RenderControl(output);

output.Write("");

control.RenderControl(output);

output.Write("");

}



private void RenderRow(HtmlTextWriter output, Label label, WebControl control)

{

output.RenderBeginTag("tr");

output.RenderBeginTag("td");

output.AddAttribute("class", "ms-formlabel");

output.AddAttribute("valign", "top");

output.AddAttribute("nowrap", "true");

label.RenderControl(output);

output.RenderEndTag();

output.RenderBeginTag("td");

output.AddAttribute("class", "ms-formbody");

control.RenderControl(output);

output.RenderEndTag();

output.RenderEndTag();

}



Both output exactly the same HTML. Does it matter? The first approach is less lines but is it any more (or less) readable? Or maybe everything should be built up in a StringBuilder class and slammed out to the HtmlTextWriter? Or is it simply whatever is readable or maintainable works? Looking for your thoughts, ideas, suggestions, rants, assorted concealed lizards of any kind.

Friday, October 10, 2008

Giving Background Dynamically for Cells in ASP.Net Report Control

Right Click in the cell and click Properties. Click on the Background color in the Property box and click expression in the dropdown box for selecting the background color.

=iif(Parameters!oTotal.Value = Fields!RowCount.Value ,"YellowGreen","White")

If Row Count and Total are equal, Background color would be YellowGreen, else White.

Giving Visibility True / False for a Report Control Row or Column

Right click in the field(cell) and click expression and add Expression as
=iif(Parameters!oTotal.Value = Fields!RowCount.Value ,False,True)


Right click in the cell again and click Properties
Click visibility tab and add expression as
=iif(Max(Fields!RowCount.Value)=5,Fields!ActualSales.Value+Fields!TOTALSales.Value,0)

Cross-forest deployments of SharePoint Portal SPS 2003

SharePoint Portal Server 2003 Cross forest deployment scenarios

One of the deployment scenarios that we were pretty naive about in SPS 2003 was the deployment of SPS in the enterprise with multiple forests. Part of why that happened was because we miscalculated how we thought AD deployments would happen.

At the beginning of the O11 planning cycle (spring 2001), we asked the AD guys about what we should support and we got a clear message that we should be targeting single forests (not because multiple forests didn't exist, but because the AD team was encouraging folks to move to a single forest). Near the end of the release cycle of O11 (summer 2003), it was pretty clear multiple forests were going to be with us for a long time. That left us with very little time to address this deployment scenario.

You can see this naivete in two different places:

People picker
Can only pick from one forest, the one in which the Sharepoint Server is deployed on

Profiles and MySites
Create a MySite and Profile page for each account even though they are for the same person
Org. Charts on the profile page contain incomplete or duplicate entries
Audience targeting works inconsistently for folks who have multiple login accounts

So what are we going to do about it?

First we reduced the many multi-forest topologies to two basic types:

1. Resource Forest
This happens when the Sharepoint deployment is done in a separate forest from the login accounts. This deployment is often driven by the way Exchange and LCS are deployed in the corporation. The Sharepoint/Exchange/LCS forest has shadown, non-login accounts that contain the metadata about the user, but the user actually logs in to a separate forest. The resource forest trusts the login forest, but not the other way around.

2. Multi-login Forests
This happens when there are one or more forests that trust each other, but a single person has accounts in more than one forest. This could happen in many ways, an instructive example is in an merger or acquisition. Both companies had their own forest and after the merger/acquisition, the forests were made to trust each together. Lots of apps depend on the forest structure, so for some people accounts are given in both forests to access the apps.

Note: The right domain should be called Domain2

Now, let's a take look at the two problem areas:

People Picker
Note: This feature is present in Beta2

For the people picker, WSS now allows you to pick people from multiple forests (even across the wrong way of a 1-way trust). The way they do this is by registering your forest and the credentials required to access it for a given Web App via the stsadm tool.

> stsadm.exe -o setproperty -url http://server:port -pn "peoplepicker-searchadforests" -pv "forest:foo.corp.com;domain:bar.foo.corp.com", LoginName, P@ssword

The people picker code will basically iterate through each and every forest (or auth provider) until is resolves a given username. This allows for a simple model to pick people across both the resource forest and multi-login forest topologies.

People and Personalization features
Note: This feature MAY not be in Beta2

Office Server has a number of resources/objects that are identified with a person -- his profile, colleagues, org. hierarchy, mysite, audiences, etc. Multiple forests generate more than one identifier for the same person - different login name, different SID.

So, the problem is how to reconcile the two accounts to one consistent user experience.

In the resource forest case:

When we import a User object from the Resource forest, we create a profile that is ID'd by resource\user1. However, we need to identify it by the real login account of the user, corp\user1, so that you can find the profile when the user logs into Sharepoint as corp\user1. If we didn't do the reconciliation, the profile would be identified by "resource\user1" and the user would be logged in as "corp\user1" and never the two shall meet.

In order to do this, we follow the DN to the master account by looking at the ms-ds-Source-Object-DN** attribute in the User object. When you setup the Directory Connection in Office Server, you will be asked for the login and password for the account that has access to the login forest.

In the Multi-login forest case:

For users who have a login account in each of the forests, we need to correctly map one login user to the other. This is easily done with the msdsSourceObjectDN attribute I mentioned earlier. However, we need to verify the user experience for each account and see whether the "right" thing has happened.

A couple of definitions for the examples to make sense:
1. There are two accounts domain1\user and domain2\user
2. They are in different forests that trust each other
3. Domain1\user is the "master" account of Domain2\user (relationship encoded in AD attribute, populated via MIIS)

Existing features and their expected behaviour:

1. Profile page and object model
Maintain the list of alternate accounts by which the profile is identified. When you try to find the profile of the user using either account, return the same profile (the one of the master account).

2. MySite
Regardless of which account you are logged-in as, creating a MySite will create one using the master account (http://server/personal/user or http://server/personal/domain1_user), but will add the alternate login account(s) as administrators to the site.

3. People Search
Search for people of either accountname (domain1\user or domain2\user) will return the same result, of domain1\user

4. Audiences
Audiences will only contain master accounts. So, during compilation, any rule that contained a slave account will get internally treated like it's master account. For example, All people reporting under "domain2\user" will get treated like "domain1\user". Since we reconcile all accounts, the management hierarchy will be exactly the same for both accounts.

5. Import from Business Data Catalog
Since we are depending on the fact that there is a master account, we will only import data into the profile store that can be identified by the master account. For example, imagine there is an HR people table or webservice. When we try to import the employee id via the BDC, the record for that employee needs to be identified by "domain1\user" not by "domain2\user".

6a. WSS Sync - Memberships
We would have to treat sites in which domain1\user is a member of as well as sites in which domain2\user is a member of as though they belong to the same user, of domain1\user. That will generate the right list of sites. That's not enough.

In order to get the right roll-up of documents and tasks, we would need to issue a query that is something is the equivalent of "SELECT docs FROM member site WHERE author = domain1\user OR author = domain2\user"

6b. WSS Sync - Profile properties
We will need to update the user table rows in the WSS site collection for both domain1\user and domain2\user. This will have the desired effect where the user goes to his MySite and uploads his picture. This info will then be sync'd to every WSS site regardless of whether the user logins in as domain1\user or domain2\user.

Thursday, July 31, 2008

Send mails from a Remote host in Classic ASP

Situation: Your IIS is sitting in a machine A and Webmail is in a remote place say Machine B. To do send the mail from Classic ASP files inside the IIS, go with the below given method. Remember, the From Email id has to be a valid id and it's User Name and Password should be mentioned it the below given code.


Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM


Function SendMailNow(sFromEmail, sToEmail,sCcEmail, sSubject, sText)

Set myMail=CreateObject("CDO.Message")
myMail.Subject = sSubject
myMail.From = sFromEmail
myMail.To = sToEmail
myMail.cc = sCcEmail
myMail.HTMLBody = sText
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "202.151.190.XX"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server ONLY A VALID USER NAME, IT SHOULD EXIST
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server PASSWORD OF AN EXISTING USER NAME IN THAT REMORT MACHINE
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

myMail.Configuration.Fields.Update

myMail.Send

Response.Write("Mail Sent")
Response.End



End Function

Send Mail from a Remote Host in Classic ASP

Situation: Your IIS is sitting in a machine A and Webmail is in a remote place say Machine B. To do send the mail from Classic ASP files inside the IIS, go with the below given method. Remember, the From Email id has to be a valid id and it's User Name and Password should be mentioned it the below given code.



<%
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM


Function SendMailNow(sFromEmail, sToEmail,sCcEmail, sSubject, sText)

Set myMail=CreateObject("CDO.Message")
myMail.Subject = sSubject
myMail.From = sFromEmail
myMail.To = sToEmail
myMail.cc = sCcEmail
myMail.HTMLBody = sText
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "202.151.190.XX"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server ONLY A VALID USER NAME, IT SHOULD EXIST
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server PASSWORD OF AN EXISTING USER NAME IN THAT REMORT MACHINE
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

myMail.Configuration.Fields.Update

myMail.Send

Response.Write("Mail Sent")
Response.End



End Function

%>

Friday, July 4, 2008

Binding DropDown List from Web.Config

Add the keys in the Web.Config under App Settings as given below.






Call up the Method BindColors() from Page Load by passing the DropDown Object

using System.Configuration; // This name space to be added in the page.
// If this is not available, Add Reference to the System.Configuration dll// from the .Net Tab by right clicking on the website and adding.
BindColors(DrpColor);

private void BindColors(DropDownList oDrp)
{
String ColorTexts = ConfigurationManager.AppSettings["ColorText"];
String ColorValues = ConfigurationManager.AppSettings["ColorValue"];

string[] ColorText = ColorTexts.Split(';');
string[] ColorValue = ColorValues.Split(';');

ListItemCollection oCollection = new ListItemCollection();

for (int i = 0; i < ColorText.Length; i++)
{
ListItem oItem = new ListItem();
oItem.Value = ColorValue[i].ToString();
oItem.Text = ColorText[i];
oCollection.Add(oItem);
}

oDrp.DataTextField = "Text";
oDrp.DataValueField = "Value";
oDrp.DataSource = oCollection;
oDrp.DataBind();
}
Dropdown’s Text and Values are bound.

Wednesday, June 25, 2008

Friday, June 20, 2008

ASP.Net Report Control.

Writting conditions in the columns; Report Control, ASP.Net.

=IIf(IsNothing(Fields!Value.Value),"NA",Fields!Value.Value)This one check if the value is Null or not.If Value is Null, it displays NA
Else it displays the Value from the Business Entity.

Thursday, June 19, 2008

Split Text In Stored Procedure and Insert in to the Table

User Selects the Select All check box and clicks Submit. All the IDs of selected check boxes are concatenated and send to the Stored Procedures.Stored Procedure accepts Two Patameters UserName and IdStringId String is in the format ~71~5~88~1043~9.
The special character '~' is used to concatenate the Ids.
Stored procedure splits the IdString and get each seperate id and update the database with the UserNameThe Table(CH_APPLIED_INFO) will be updated as

UserName JobID
Sabin 71
Sabin 5
Sabin 88
Sabin 1043
Sabin 9

This SP is communicative / Userfriendly. It accepts two parameters, UserName, which is a string and an IdString which is a '~' Concatenated String of JOB IDs the user have been selectd through the Check boxes in the Job listing Page.//Format of the IdString is ~71~5~88~1043~9

CREATE PROCEDURE dbo.SplitAndInsert
(
@userName varchar(100),
@idString varchar(100)
)
AS
SET NOCOUNT ON
DECLARE @splitstring varchar(100)
DECLARE @substring varchar(50)
Set @splitstring = @idString
WHILE (CHARINDEX('~',@splitstring ,1)<>0)
BEGIN
SET @substring = substring(@splitstring ,1,CHARINDEX('~',@splitstring ,1)-1)-- Find Substring up to Separator
PRINT @substringif @substring <> 0
INSERT INTO CH_APPLIED_INFO(USER_NAME, JOB_ID)
VALUES (@userName,@substring)SET @splitstring = substring(@splitstring ,Len(@substring)+2,Len(@splitstring ))
-- SET The Original String after the Split END
SET NOCOUNT OFF
RETURN

Tuesday, June 10, 2008

Transaction Scope Settings


You may open Control Panel\Administrative Tools\Component Services.
Select Component Services\Computer\My Computer,
right-click and choose Properties.
On the MSDTC tab, press "Security Configuration..." and check if following options are enabled

Network DTC Access
Under Client and Administration >

Allow Remote Clients, Allow Remote Administration

Under Transaction Manager

CommunicationAllow
InboundAllow
OutboundNo


Authentication Required Enale XA Transactions
And then reboot your computer and test again.

Here is the Snippet for implementing Transaction Scope for Rolling out the Changes.

using (TransactionScope scope = new TransactionScope())
{
try
{ }
catch (Exception ex)
{
throw new Exception("Application cannot Save the entry as the mandatory fields are not filled");
} scope.Complete();


http://msdn.microsoft.com/en-us/library/ms172152.aspx (Microsoft Pulled out this Page, I guess. )

Thursday, April 24, 2008

The type or namespace name 'Transactions' doesnot exist in the namespace 'System'




The type or namespace name 'Transactions' doesnot exist in the namespace 'System' (are you missing an assembly reference



Cause : You are missing a DLL.

Solution : This can be added by adding reference by right clicking in the solution in the Visual studio IDE. After adding this one, you can see the change in the Web.config file. You will see a new assembly been added there..


















Tuesday, April 22, 2008

sys.WebForms.PageRequestManagerParserErrorException:

sys.WebForms.PageRequestManagerParserErrorException: The message receieved from server could not be parsed. Common causes for this error are when the response is modified by calls to Response filters, HttpModules, or server trace is enabled.

There are a couple of solutions available to this error:
Try to put yur Sumbit button out of the Update Panel.

do not use the HttpModule and rely on IIS compression, or move the application to the .NET Framework 3.5.
Remove the HttpModule from web.config
Assure ScriptResource is not compressed:
Open the IIS Manager
Right click on "Web Sites" folder > Properties
Click the "Services" tab
Check "Compress application files" and "Compress static files"
Apply and confirm all dialogs
Stop IIS
Open a command prompt and go to C:\Inetpub\AdminScripts
Run the following commands to add .js, .aspx and .axd to the compression list:
cscript adsutil.vbs set W3SVC/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "js"
cscript adsutil.vbs set W3SVC/Filters/Compression/Deflate/HcFileExtensions "htm" "html" "txt" "js"
cscript adsutil.vbs set W3SVC/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
cscript adsutil.vbs set W3SVC/Filters/Compression/Deflate/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
Restart IIS
You can also move the application to .NET Framework 3.5 instead, because the UpdatePanel control has been changed internally and now this problem should not happen anymore.

Monday, April 14, 2008

The Name 'Request' does not exist in the current context

Nothing to worry about, since you can still access these properties, but using a different path.For example to access a cookie with the name MyCookie you would normally use Request.Cookies["MyCookie"]; however, if the error The name 'Request' does not exist in the current context is returned, use the following path for retrieving the cookie:
System.Web.HttpContext.Current.Request.Cookies["MyCookie"].value;

Friday, April 4, 2008

Difference between the Web.config of a ASP.Net Website and an ASP.NET AJAX Enabled Website

When you create a new AJAX-enabled Web site, you can use the Web.config file provided in the installation package to add the required configuration settings. In Visual Studio, the Web.config file for Microsoft ASP.NET AJAX is included in your project when you create a new ASP.NET AJAX-enabled Web Site. But in a Normal ASP.Net Ajax website, you need to add it manually by right clicking on the Website in the Solution explorer.

Adding ASP.NET AJAX Configuration Elements to an Existing Web Site
In an existing Web site, you typically have values in the Web.config file that you want to retain. In that case, you can add the new ASP.NET AJAX elements into the existing Web.config file.
The new elements are part of the following configuration sections:
The element
The element
The element
The element
The element
The element
The element

Friday, January 11, 2008

Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc

Ok I Don't know how it's working now for me but here what i did....
1. Install the latest Asp.NET Ajax
2.Open my web.config in my production server and replace this line

by

It's the same thing but the PublicKeyToken is in capitals....
Save it and browse to my site and bingo!
Hope this help...

Tuesday, January 8, 2008

SQL Developer Installation Error

The application failed to initialise properly (0xc0000018). Click on OK to terminate the application

The set up is for x32. It wont work in 64 Bit Os. Get a setup which suits for x64

Unable to find the requested .NetFrameWork Data Provider. It may not be installed.

Problem is that, your Operating System will be of 64 bit. x64.