Tuesday, August 10, 2010
Using a Stored Procedure in Entity Framework 4
In LINQ all you had to do is to drag the stored procedure from your Server Explorer respective data connection on your model diagram.
In entity framework 4, there are few steps and they are different.
1. On your entity diagram in visual studio, right click and choose Update Model from database.
2. Add your stored procedure from the wizard. What it does, it adds the proc to your diagram. Its not visible in .Net code yet.
If you go to Model Browser > {EntityModel}.Store > Stored Procedures, it should be visible in there now
3. Right click, Add > Function Import. Complete this according to your requirement, name of the proc you want to see in .Net, which stored proc it maps to and what is the collection it returns etc.
After step 3 you can access access the proc using an instance of context.
For more visual representation of the steps, please visit WebLog of Ken Cox
Wednesday, August 4, 2010
Extracting tags from xhtml content
Following code will get you title using regular expression
Regex regex = new Regex("<title>(?<title>.*?)</title>", RegexOptions.IgnoreCase);Following code will get you meta tag My_Meta
Match titleMatch = regex.Match(html);
string title = titleMatch.Groups["title"].Value;
Thursday, July 15, 2010
Saving objects using Entity framework
tableObject.property1 = "Hello";
tableObject.proeprty2 = "World";
// NOTE: make sure to use the same instance of entityContextObject which was used to populate the tableObject (e.g. updating back to database)
entityContextObject.AddToTableClass(tableObject);
entityContextObject.SaveChanges();
Monday, June 28, 2010
Accessing email settings from web.config
Wednesday, March 31, 2010
outputting all attributes except one in xsl
Monday, October 5, 2009
Framework Design Guidelines - .Net
Link: http://channel9.msdn.com/pdc2008/PC58/
Tuesday, September 29, 2009
Website vs Web Application VS 2008
Found this post which explains why it happens. Website model doesn't have designer files and are compiled on demand in single dlls. When you build a web application, it builds as one dll and maintain UI elements relation with code behind using designer files.
The link attached below explains how to do it, worked for me! So now I have decided that I'll use Web application instead of Website since its not suggested for non-smaller web applications.
Link: Detail Post by Guru Stop
Friday, September 25, 2009
How to get jQuery intellisense working VS2008
While searching for the solution I found this post from MWTech
Steps from the post are:
Getting jQuery Intellisense Up & Running
1. Ensure that VS2008 SP1 is installed. (Further info)
2. Ensure that Hotfix KB958502 is installed. (Further info)
3. Install the jQuery library into your project. It'll have a filename like "jquery-1.3.2.js".
4. Install the jQuery Intellisense file into your project. It may very well have a filename like "jquery-1.3.2-vsdoc2.js" but must be renamed to be identical to the jQuery library name, plus "-vsdoc". Thus in this example, it must be renamed to "jquery-1.3.2-vsdoc.js".
5. Provide a reference to the jQuery library. There are generally two ways to do this, both of which are described below.
6. In external Javascript files a direct reference to the jQuery Intellisense file must be made. More details are provided below.
Works perfectly! Have a look at the complete post if you are having same issues.
Wednesday, September 9, 2009
.NET IoC Container Comparisons
Link: Part1
Link: Part2
Got the links from StackOverFlow post.
Wednesday, September 2, 2009
Is User member of AD group - VBA
Quote:
Function IsMember(strDomain As String, strGroup _Thanks to Greg Reddick Link: http://my.advisor.com/doc/08691
As String, strMember As String) As Boolean
Dim grp As Object
Dim strPath As String
strPath = "WinNT://" & strDomain & "/"
Set grp = GetObject(strPath & strGroup & ",group")
IsMember = grp.IsMember(strPath & strMember)
End Function
Thursday, July 30, 2009
How do you convert a string into an enum?
I found the solution on Tim Sneath's blog. I like one liners :), using it replaced bunch of code, in my case 10 cases (could be more or less depending on how many Enum values you have).
Quote:enum Colour
{
Red,
Green,
Blue
}
// ...
Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true);
Please visit Tim's blog post if you would like to read the full post.
Monday, September 15, 2008
Response.End and download file problem using asp.net code inside sharepoint
Issue:
To download file from Sharepoint doesn’t work but works fine in plain asp.net environment.
Solution:
Solution is very simple, Add the following code for the button or link which initiates the download:
MyButton.OnClientClick = "document.getElementById(""" & Me.Page.Form.ClientID & """).onsubmit = function() {return true;}"
Friday, September 12, 2008
Impersonating in Windows (WinForm)
Impersonating in asp.net is as simple as just adding a tag in web.config but in windows I found few links which were using kernel dll to impersonate. Article I found on theserverside.net shows new features in .net 2.0 which makes it very easy to do this.
Quote:
System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(); SecureString ss = new SecureString(); ... append password characters pInfo.Password = ss; pInfo.UserName = @"domain\alice"; pInfo.FileName = @"c:\windows\notepad.exe"; pInfo.UseShellExecute = false; Process.Start(pInfo); Link: http://www.theserverside.net/tt/articles/showarticle.tss?id=NewSecurityFeatures
Wednesday, September 10, 2008
SPTraceView - Lightweight Tool for Monitoring the SharePoint Diagnostic Logging in Real-Time
Very small application, only 65kb zip, great tool for SharePoint diagnostic tracing
Quote:
SPTraceView moniors in real time all SharePoint diagnostic tracing (also called ULS tracing) and can notify you using a balloon-style messages in the tray bar when any information of particular interest to you is sent (traced) by any of the MOSS services and components.
Saturday, September 6, 2008
OLE DB Connection string issue using Excel
I came across two issues while trying to load a excel file in asp.net. I'll explain both of them separately.
1). Exception: The Microsoft Jet database engine could not find the object
This exception happens when the path is not fully qualified to the excel file used in the oledb connection string. Without path, its not going to through an exception while creating connection.
Before: Dim dsn As String = "provider=Microsoft.Jet.OLEDB.4.0;data source='MyFile.xls'; Extended Properties=""Excel 8.0;HDR=NO;"""
After: Dim dsn As String = "provider=Microsoft.Jet.OLEDB.4.0;data source='" & Server.MapPath("MyFile.xls") & "'; Extended Properties=""Excel 8.0;HDR=NO;"""
Solution: use Server.MaptPath to get fully qualified path to a file to avoid this exception.
2). Exception: Could not find installable ISAM.
When using extended properties be careful with the syntax
Before: Dim dsn As String = "provider=Microsoft.Jet.OLEDB.4.0;data source='MyFile.xls'; Extended Properties=Excel 8.0;HDR=NO;"
After: Dim dsn As String = "provider=Microsoft.Jet.OLEDB.4.0;data source='" & Server.MapPath("MyFile.xls") & "'; Extended Properties=""Excel 8.0;HDR=NO;"""
Solution: use quotes around the value of extended properties. If the syntax is wrong, it tries to look for another driver.
Thursday, August 28, 2008
Store user information on J2ME platform
Problem:
J2ME doesn’t support property files
Solution:
In J2SE properties file can be used to store information but that’s not available on J2ME platform, instead it provides a record store. A sample is available at Sun website.
Sample Link: http://developers.sun.com/mobility/midp/samples/#persist
Problem:
Export excel file from SQL Server 2005. In order to do SQL gave the attached error.
Solution:
Quote: (MSDN)
“By default, SQL Server does not allow ad hoc distributed queries using OPENROWSET and OPENDATASOURCE. When this option is set to 1, SQL Server allows ad hoc access. When this option is not set or is set to 0, SQL Server does not allow ad hoc access.”
MSDN Link: http://msdn.microsoft.com/en-us/library/ms187569.aspx
In order to turn this option on follow the link below
http://www.kodyaz.com/articles/enable-Ad-Hoc-Distributed-Queries.aspx
Tuesday, August 26, 2008
HTTP Post multipart file upload with J2ME
Task:
Upload images from a blackberry device to a website
Solution:
There are a lot of tutorials available to upload form data to a website but we spent sometime looking to post a file to a web server using Multi part. Found the article at Nokia which does the job exactly what we need to do. It’s a very to the point code sample with also a usage sample. Also attaching the code as a zip file incase the link is broken and because the site didn’t have a code download option. All credit goes to Nokia.
Link: http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_with_J2ME
Wednesday, August 20, 2008
ShowDialog Memory leak in WinForm
Recently we had to use a common form to display all the reports for a windows application. For some reason all the reports would work only once. We were using a ReportForm.ShowDialog() to show the report form. Apparently ShowDialog doesn’t dispose the form when its closed as a normal form does when its shown using Form.Visible = True. After a lot of search I came across the article which mentioned that there is a memory leak issue if you don’t dispose the form properly after ShowDialog.
Best Practice according to the article is open the form using the following code and it works, solved our issue.
Quote:
using( SomeDialog sd = new SomeDialog() )
{
sd.ShowDialog();
}
Link:
http://kevin-berridge.blogspot.com/2007_08_01_archive.html
SharePoint Object Browser
Code project article for Sharepoint object browser. It comes very handy when doing programming with sharepoint.
Link:
http://www.codeproject.com/KB/sharepoint/sharepoint_object_browser.aspx