Pages

Showing posts with label Tutorials. Show all posts
Showing posts with label Tutorials. Show all posts

Mime Content Types for office 2007 documents

The Content Type of the office 2007 files are different from the normal office documents. the files are strored and maintained internally as xml formats. While uploading these documents they are uploaded in octet stream[binary stream].
For more details check this link. openxmldeveloper.org

The Content Types of the office 2007 files is listed below.

File ExtensionContent Type
docmapplication/vnd.ms-word.document.macroEnabled.12
docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
dotmapplication/vnd.ms-word.template.macroEnabled.12
dotxapplication/vnd.openxmlformats-officedocument.wordprocessingml.template
ppsmapplication/vnd.ms-powerpoint.slideshow.macroEnabled.12
ppsxapplication/vnd.openxmlformats-officedocument.presentationml.slideshow
pptmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12
pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
xlsbapplication/vnd.ms-excel.sheet.binary.macroEnabled.12
xlsmapplication/vnd.ms-excel.sheet.macroEnabled.12
xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xpsapplication/vnd.ms-xpsdocument

ForEach File Enumerator

It is a Container element in control flow group in the SSIS. The container iterats through the object collection it belongs to. The ForEach File Enumerator iterates all files and directories in a specifies directory. Let us wal through that with an example.

.Create a new package.
.Drag and Drop the Foreach Loop Container from the Toolbar.
.Right Click, Edit the Container Properties.
.In General tab, set the name of the container

.In Collection Tab, set the Enumerator to Foreach File Enumerator. Set the Folder path to the required path. the Files field can be used to filter the type of files. the file name retrieval format can be set. suppose if the specified contains sub folders and if we want to check inside those folders also then check the "Traverse subfolders" Check Box.
.In Variable Mappings tab, Create a new variable, for example "Var" with datatype as string.

also set the index to 0, as the collection manipulates with one object in a loop cycle.

.The Container is set and ready to use, let us check the container using script task.
.Place a Script Task inside the Foreach Loop Container.
.Right Click, Edit the task.
.Goto to Script tab, and set the ReadOnly Variable Field with the variable used in the Foreach Loop. here set to "Var".

.Click Design Script from the Script tab, a new VS window environment opens with pre set already.
.Type the content, as given below in the existing function
Public Sub Main()
MsgBox(Dts.Variables("User::Var").Value.ToString())
Dts.TaskResult = Dts.Results.Success
End Sub

.Save it, close the environment and click OK in the container Property box.
.The sript task will be evaluvated on every loop cycle. the loop object is passed as a read only parameter for script task. the main functioin in the task displays the value stored in the variable. In this way we can do file or manipulation kind of task through the SSIS. when the package is runed, the files in the specfied folder are displayed as message box to the end user.

SSIS - For Loop Container

This works on the tradition counter logic, where it has 3 steps.
1. Intialization,
2. Incrementation,
3. Condition.
Let us see in detail, Stepwise...
. Drag and Drop a For Loop Container from the toolbox to the Control Flow Tab
. Select the Container, add a variable from the Variable box. Variable box can be obtained from the Menu SSIS->Variables. say variable name is "count" of data type int.
(When we select the container and create a variable the scope of the variable is set only for Container level, means the variable will not be available for other components outside the container.)
. Right Click on the container and select Edit from the Context Menu displayed.
. In the InitExpression, Enter @[User::count]=0. this assigns the value 0 to the user created variable count.
. In the Eval Expression, Enter @[User::Variable] <10. this sets the loop condition.
. In the Assign Expression, Enter @[User::Variable] = @[User::Variable]+1. this increments the value of the variable by 1 for every loop.
. Select Ok and close the Dialog.
. From the tool box, place a script task in the container.
. Right Click the script task and select edit from the context menu.
. Goto script tab in the left panel.
. Click Design Script button located in the right bottom of the dialog. this opens a vb code page with new studio environment with some code writen already.
. Place the code MsgBox("hai"), in the main subroutine, before the assignment of task result.
. save a close the environment.
. Click ok and close the script edit dialog.
. Right Click the container, select execute container from the context menu.
. this runs the For Loop Container, and the tasks inside it. it displays the Hai message box 10 times and stops the execution.

This example explains the feature of the For Loop Container in a simple, how ever we can use this as per our need in the package.

SSIS - Expession Builder

It is an Editor, which creates expression using the variables and In-Built functions. Normally this editor can be reached for all elements in the package. the button with "..." [3 dots] is clicked to open this editor.
The property of the elements are set directly by assiging values to them, or by setting a expression and the expression is evaluvated in the runtime to set the values.
Almost every control's editor will have a Expressions tab, which can be selected, the tab contains a Field group named Expressions, by selecting the triple dot button again, will opens a Property Expression Editor. this contains two columns. first column contains drop down list, from which a field name can be selected and the second column contains a triple dot button, which actually opens a Expression Builder.
Expression Builder Editor contains 5 blocks.
1. Variable - list of variables available within the scope is listed.
2. Built in functions - list of functions are organized in groups and listed.
3. Description - displays a description of built in function, which is currently selected[Read only]
4. Expression - variables and functions can be dragged and droped here or expression can be manually keyed in.
5. Evaluvated Value - the value of the expression will be displayed, when the evaluvate expression is clicked, which throws exception if the expression is not set correctly.

The Built In Functions block will have type casting symbols and also the supported operators for evaluvating the expression.
once the expression is created succesfully the dialog can be closed, and the expression is assigned to the field. we can assign expressions to any no of fields.

SSIS - Precedence Contraints

. It is link created between the Containers, executables, tasks or any control flow elements.
. For example, to view a Precedence Constarint Editor, create two script tasks.
. select a task, it displays a arrows pointing downwards, drag and drop the arrow to the second script task.
. a conector is created in between the tasks. it is called Precedence constaint.
. the default value set to the constraint is success.
. to view the editor, select the connector, right click and select edit from the context menu.
. a dialog box opens with fields, evaluvation operation, constaint and expression.
. the flow can set as per the condition defined here.
. the condition can be set to Constraint, with following values,
1. Success - allows to flow only if the previous task executed succesfully.
2. Failure - allows to flow only if the previous task fail to execute.
3. Completion - allows to flow, without considering the execute status of previous task.
. the condition can be set to Expression. the flow depends on the result of the expression.
. the condition can be set to Constaint or Expression, where both will be defined and flow will be decided by any one.
. the condition can be set to Constraint and Expression, where both will be defined and flow will proceed only if both are passed.
. Multiple Precedence Constraints may contain for a task, in that case the logical Or and And between the Precedence Constraints can also be set using the editor.

SSIS - Control Flow Items

Control Flow Items contains Containers and Tasks.
. Containers are Components which holds the tasks and the task will be executed as per the containers nature.
. Tasks are activity which performs a action.
. SSIS supports various type of tasks related to database, file system, process, web service, FTP, Xml, Sql jobs, message queues.
. Each task can be ordered, or aranged in sequence like one after the other or in parellel using Precedence Constraints.
. Container helps to execute repeative tasks, and also to make a group of task over package.

Debug Visual C++ ActiveX DLL [Web component]

The ActiveX dll can be debugged using test container. It is a in-built tool with VC++, Visual Studio IDE. we can set the debug environment in order to use this. In the project properties, go to Debug section, then select the "command" property and set the value as test container from the drop down list. so, when the application is build and run, Test Container application is invoked and we can add the dll component from a avalable list of components. once selected and added in the container, the GUI part is it will be like a box, but the methods can be invoked and tested for functionality.
This is one way for testing using Test Container tool.
If the component is web based, then In project properties->Debug Section set the value to Internet Explorer for "command" property. once it is set and run, the build will be made and the Internet explorer will be opened with blank url. enter the url of the page where ActiveX component is used. this will opens the component in debug Mode. Before starting this, let us see the environment. the ActiveX component wil be installed for the first time in client system, or else when the page is opened the object will be downloaded and installed in the location as mentioned by the devoloper. once it is installed, it will used for succesive calls of the same page, untill client uninstalls the control. Before stating the debug process, the newly build dll and the corresponding pdb file has to be placed in the location where the application installed the component while it is rendered. Now the enviro is set and redy to work, Run the project, it opens the url. place the debug point wherever needed, enter the required page url in th eopened browser and it stops when the debug point reaches.
1. Set the Project property for Debug section->Command to Iexplore.exe
2. Build the component.
3. After successful build copy the dll and correspoding pdb file in the Component installed location.
4. Place the debug points as required.
5. Run the application, it stops at the Break point.

js File Compressor for ASP.Net applications



Create a WebSite, or Add a reference of the dll to the WebSite.

In Web.Config file a new httpHandler in HttpHandlers Section.

<add path="*.js"
type="ClassLibrary1.Handler, ClassLibrary1, Version=1.0.0.0, Culture=neutral"
validate="false" verb="*">

That's all, rest of the work will be done by our Handler.
Let us see how it works,

Basically the HttpHandlers are used to handle the request of the WebApplication.
This Handler is to handle the javascript file. it removes the white spaces, new line characters, inline comments and multiline comments. the Handlers class is inherited from the IHttpHandler Interface, it implements ProcessRequest method.

//Getting the script file name from request
Uri url = context.Request.Url;
string filename = url.Segments[url.Segments.Length-1];

//Creating a file stream to read the script file.
FileStream fs = new FileStream(context.Server.MapPath(filename), FileMode.Open);
StreamReader sr = new StreamReader(fs);
string js = sr.ReadToEnd();
string a = string.Empty , b = string.Empty;
//Removing the single line comments
while (js.IndexOf("//")!=-1)
{
a = js.Substring(0, js.IndexOf("//"));
b = js.Substring(js.IndexOf("\r\n", js.IndexOf("//")));
js = a+b;
}
//Removing multiline comments
while (js.IndexOf("/*") != -1)
{
a = js.Substring(0, js.IndexOf("/*"));
b = js.Substring(js.IndexOf("*/", js.IndexOf("/*"))+2);
js = a + b;
}
//To Remove Blank spaces
js = js.Replace(" ", string.Empty);
//To remove Carrige retun and new line character
js = js.Replace("\r", string.Empty);
js = js.Replace("\n", string.Empty);
//Flushing it in response
context.Response.Write(js);
//Closing the resourses used
sr.Close();
fs.Close();
sr.Dispose();
fs.Dispose();

You can get the same from my article in CodeProject

Dispose Vs Finalizer

The Dispose and Finalizer are methods used to clear the resources used for the object.
The Dispose is a method of IDisposable interface. we have to inherit this interface for our object and implement the method Dispose, to clear our objects used in our application. suppose if we use collection and dictionary or any other huge resource for a specific object, we have to clear all the memory used by the object when it is destroyed. to make this happen internallly for every object we have to implement Dispose method and it takes care of the clearing the memory.
The Finalizer method is also similar type but this will be called when GC gets invoked. this GC.Collect call will invoke Finalizer method for each and every object. this will do a emergency clean, it may lead to data loss some times.

we can also implement finalizer method as a special case. the call of finalizer method after a dipose is a waste of process time, we can bypass this action by setting the property SupressFinalizer to true. this will help to avoid calling the finalizer method when GC gets activated.

Online Resources Available, Use It and Celebrate

Some of the Resource Sites, where we can learn..
[Contribution is not Mine, original link]

ASP.NET Quickstart Tutorial
http://www.asp.net/QuickStart/aspnet/doc/whatsnew.aspx

Virtual Labs
http://msdn.microsoft.com/virtuallabs/asp2/http://msdn.microsoft.com/virtuallabs/fritzonion/
“How Do I” Video Series
ASP.NET HOW DO I Video Series: Caching (Part 1)
ASP.NET HOW DO I Video Series: Caching (Part 2)
ASP.NET HOW DO I Video Series: Create a Full-Featured Customer Login Portal
ASP.NET HOW DO I Video Series: Data
ASP.NET HOW DO I Video Series: Form Building for a "Contact Us" Page
ASP.NET HOW DO I Video Series: Localization
ASP.NET HOW DO I Video Series: Master Pages and Site Navigation
ASP.NET HOW DO I Video Series: Membership and Roles
ASP.NET HOW DO I Video Series: Profiles and Themes
ASP.NET HOW DO I Video Series: Tips and Tricks
ASP.NET HOW DO I Video Series: Web Parts and Personalization

How-To MSDN Articles
How To: Configure the Machine Key in ASP.NET 2.0
How To: Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0
How To: Create a Service Account for an ASP.NET 2.0 Application
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA
How To: Instrument ASP.NET 2.0 Applications for Security
How To: Improve Security When Hosting Multiple Applications in ASP.NET 2.0
How To: Perform a Security Deployment Review for ASP.NET 2.0
How To: Prevent Cross-Site Scripting in ASP.NET
How To: Protect Forms Authentication in ASP.NET 2.0
How To: Protect From Injection Attacks in ASP.NET
How To: Protect From SQL Injection in ASP.NET
How To: Use ADAM for Roles in ASP.NET 2.0
How To: Use Authorization Manager (AzMan) with ASP.NET 2.0
How To: Use Code Access Security in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in Multiple Domains in ASP.NET 2.0
How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
How To: Use Health Monitoring in ASP.NET 2.0
How To: Use Impersonation and Delegation in ASP.NET 2.0
How To: Use Membership in ASP.NET 2.0
How To: Use the Network Service Account to Access Resources in ASP.NET
How To: Use Protocol Transition and Constrained Delegation in ASP.NET 2.0
How To: Use Regular Expressions to Constrain Input in ASP.NET
How To: Use Role Manager in ASP.NET 2.0
How To: Use Windows Authentication in ASP.NET 2.0

Authentication and Authorization
How To: Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0
How To: Create GenericPrincipal Objects with Forms Authentication
How To: Protect Forms Authentication in ASP.NET 2.0
How To: Use Authorization Manager (AzMan) with ASP.NET 2.0
How To: Use Forms Authentication with Active Directory
How To: Use Forms Authentication with Active Directory in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in Multiple Domains in ASP.NET 2.0
How To: Use Forms Authentication with SQL Server 2000
How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
How To: Use Windows Authentication in ASP.NET 2.0

Code Access Security
How To: Create a Custom Encryption Permission
How To: Use Code Access Security in ASP.NET 2.0
How To: Use Code Access Security Policy to Constrain an Assembly

Code Review
How To: Perform a Security Code Review for Managed Code (Baseline Activity)

Communications Security
How To: Call a Web Service Using Client Certificates from ASP.NET
How To: Call a Web Service Using SSL
How To: Set Up SSL on a Web Server
How To: Set Up Client Certificates
How To: Use IPSec for Filtering Ports and Authentication
How To: Use IPSec to Provide Secure Communication Between Two Servers
How To: Use SSL to Secure Communication with SQL Server 2000

Configuration
How To: Create a Custom Account To Run ASP.NET
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA

Cryptography
How To: Create a DPAPI Library
How To: Create an Encryption Library
How To: Store an Encrypted Connection String in the Registry
How To: Use DPAPI (Machine Store) from ASP.NET
How To: Use DPAPI (User Store) from ASP.NET with Enterprise Services

Deployment Review
How To: Perform a Security Deployment Review for ASP.NET 2.0

Impersonation and Delegation
How To: Implement Kerberos Delegation for Windows 2000
How To: Use Impersonation and Delegation in ASP.NET 2.0

Input and Data Validation
How To: Prevent Cross-Site Scripting in ASP.NET
How To: Protect From Injection Attacks in ASP.NET
How To: Protect From SQL Injection in ASP.NET
How To: Use Regular Expressions to Constrain Input in ASP.NET

Patching and Updating
How To: Implement Patch Management

SQL Server 2000
How To: Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0
How To: Protect From SQL Injection in ASP.NET
How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
How To: Use SSL to Secure Communication with SQL Server 2000

Threat Modeling
How To: Create a Threat Model for a Web Application at Design Time

ATLAS (ASP.NET AJAX)
Quickstart Developer Tasks
http://ajax.asp.net/

“How Do I?” Videos
http://ajax.asp.net/default.aspx?tabid=47&subtabid=478#howdoi

Preview Videos
http://ajax.asp.net/default.aspx?tabid=47&subtabid=478#atlas

Samples
http://go.microsoft.com/fwlink/?LinkId=62605

Control Toolkit
http://atlas.asp.net/default.aspx?tabid=47&subtabid=477

Enjoy by doing R&D