Feeds:
Posts
Comments

Archive for the ‘Code’ Category

Let’s Say you have 2 SharePoint Lists

ParentList

-ID
-Name
-Details

ChildList

-ID
-ParentID
-Comment

Assume you want to display a list of comments with the name of the associated Name from the Parent List in a gallery

Set the Gallery Items to

AddColumns(
    'ChildList',
    "ParentInfo",
    Lookup(
        ParentList,
        ID='ChildList'[@ParentID]
     )
)

This way, in the Gallery, for each row you will find a new field of type record named “ParentInfo”. so you can add columns as ‘ParentInfo’.Name

Read Full Post »

here is a simple code to load an image coming from a web service as byte array

In the html Add this snippet

   <a v-on:click="getQR">Get QR</a>

   <img id="qr" :src="qrImg" />

And add this snippet to the methods section in vuejs

getQR() {
      var base = this;
      axios
        .get(your api url + "/QRCode", { responseType: "arraybuffer" })
        .then(function (response) {

          let base64String = btoa(
            String.fromCharCode.apply(null, new Uint8Array(response.data))
          );
          base.qrImg = "data:image/jpg;base64," + base64String;
        });
    },

Read Full Post »

In order to replace a text in any section of the header or the footer of a word document, you can use this snippet

doc = Document Object

foreach (Section sec in doc.Sections)
{
foreach (HeaderFooter fot in sec.Footers)
{
fot.Range.Find.Execute(FindText: loc.Key, ReplaceWith: loc.Value,
Replace: WdReplace.wdReplaceAll);
}
}

Read Full Post »

In order to grant authenticated FBA users access to a custom application page (/_layouts page), please follow these steps:

  • The Page should inherit from LayoutsPageBase (Making it inherit from UnsecuredLayoutsPageBase will grant anonymous access to this page).
  • Override the Properties RightsRequired and RequireDefaultLayoutsRights

       protected override SPBasePermissions RightsRequired
       {
           get
           {
               SPBasePermissions permissionRequired = SPBasePermissions.ViewPages;
               return permissionRequired;
           }
       }

       protected override bool RequireDefaultLayoutsRights
       {
           get
           {
               return false;
           }
       }

 

This will grant authenticated FBA users access to this _Layouts page.

Read Full Post »

http://visualstudiogallery.msdn.microsoft.com/en-us/76293c4d-8c16-4f4a-aee6-21f83a571496

Read Full Post »

YouTube just released an .NET SDK for YouTube.
http://apiblog.youtube.com/2010/02/announcing-youtube-sdk-for-net.html
It includes a VS2008 template to develop YouTube Applications as well as some sample applications

Read Full Post »

.NET stock Trader is a sample application showing a host of .NET technologies using Service oriented and N-tier designs:

A set of videos to demonstrate the application are posted to Channel 9: http://channel9.msdn.com/posts/Charles/Greg-Leake-Stocktrader-A-Loosely-coupled-and-Interoperable-NET-Enterprise-Services-Sample-Applic/

An overview about the application can be found at: http://msdn.microsoft.com/en-us/netframework/bb499684.aspx

A discussion forum for .NET StockTrader is available at: http://social.msdn.microsoft.com/forums/en-US/dotnetstocktradersampleapplication/threads/

Read Full Post »

ASP.NET Add-in for best practices analyzer : http://www.codeplex.com/Wiki/View.aspx?ProjectName=BPAEngine

Tool to show useful information about an assembly when right clicking on it  (Debug or release, Version, public token, etc.) : http://www.codeplex.com/AssemblyInformation

Patterns and Practices guidance explorer: http://www.codeplex.com/guidanceExplorer

Patterns and Practices SharePoint guidance:http://spg.codeplex.com/

Tool to visualize the project dependencies in a solution: http://www.codeplex.com/dependencyvisualizer

Read Full Post »

Regionerate: a small add-in that will help you manage the code order and layout: http://visualstudiogallery.msdn.microsoft.com/en-us/800978aa-2aac-4440-8bdf-6d1a76a5c23c

StyleCop: Tool the check code style and consistency: http://code.msdn.microsoft.com/sourceanalysis

Read Full Post »

This tutorial will very quickly walk through creating a VERY SIMPLE  Entity Model. This is a VERY simple tutorial to simply get a taste of EF.

You will need visual Studio 2008 SP1 or later and SQL Server for the database and we will use the Nrothwind sample database.

ScreenHunter_01 Mar. 19 00.09

Open Visual Studio 2008:

ScreenHunter_02 Mar. 19 00.09

Create a new Project: (Make sure you are selecting Framework version 3.5)

ScreenHunter_03 Mar. 19 00.10

Right Click the Project Name and Select “Add Item”, Select ADO.NET Entity Data Model from the “Data” Category and select a name for it

ScreenHunter_05 Mar. 19 00.11

A Wizard will start, Please select “Generate from Database” (Note: Though theoretically, you can start with the Model and the Later on map it to the a database, The Visual studio tools for EF are best designed in this current release to generate the mode from the database.

ScreenHunter_06 Mar. 19 00.11

The Next form will ask you to create the connection to the database Or choose from an existing connection in the project if one exists:

ScreenHunter_07 Mar. 19 00.11

Create the connection. Note that the wizard automatically creates a key in the web.config or app.config with the connection string inside it (nice feature)

Next you will be asked To select the Tables/Views/Procedures that you want to include in the Entity Data Model and to se a namespace for the Model Classes:

ScreenHunter_09 Mar. 19 00.13

In Our case we will simply Select the “products” and “Categories” Tables from the List of tables available in the Northwind database. (This is just for simplicity).

Based on the choice, the Wizard will generate the Entity data model.

ScreenHunter_10 Mar. 19 00.17

To make the Model more easy to understand and more natural, you can set the name for the Entity (Product as opposed to products like the table name in the database) and the Name of the Entity Set (we can make it Products or ProductSet or whatever)

ScreenHunter_11 Mar. 19 00.28

You can also change the Class properties, For example, you can rename ProductName (as in the column name in the DB) to be “Name” to be more natural to write code like productObj.Name rather than productObj.ProductName for example.

 

Now the model is ready we can start retrieving data.

A very simple code to load all products will look like this:

using (NorthwindDBConn context = new NorthwindDBConn())
{
    foreach (Product prod in context.Products)
    {
        Console.WriteLine(prod.Name);
    }
}

Important Note: Though prod Object has a category property, due to Lazy loading by the EF it will e initialized as null and wont be fetched from the database.

In order to read it from the database and make sure it is initialized, you need to add the line “ prod.CategoryReference.Load(); “ so the code will look like :

 

using (NorthwindDBConn context = new NorthwindDBConn())
{
    foreach (Product prod in context.Products)
    {
        prod.CategoryReference.Load();
        Console.WriteLine(prod.Name);
    }
}

 

That is All you need to retrieve elements from EF. To use more sophisticated queries, EF allows you to use LINQ to build queries.

 

In order to save an Product object for example, all you nee to do is:

using (NorthwindDBConn context = new NorthwindDBConn())
    {
        Product x = new Product();
        x.Name = "New Product";

        context.AddToProducts(x);

        context.SaveChanges();
    }

 

That is all you need to get started with the EF.

For more information you can refer to:

Read Full Post »

Older Posts »