Get possible outcomes for a nintex multi – Task

Here is a way how to retrive the possible outcomes for a nintex task dynamically:

1
2
3
NintexTask task = NintexTask.RetrieveTask(ctx.TaskItem.ID, ctx.TaskItem.Web, ctx.TaskItem.ParentList);
Approver approv = task.Approvers.GetBySPId(ctx.TaskItem.ID);
ConfiguredOutcomeCollection outcomes = approv.AvailableOutcomeInfo.AvailableOutcomes;

How to set Multi – Lookupfields programmatically

Here is a way how you can set Multi – Lookupfields programmatically

1
2
3
4
5
6
7
8
9
10
11
12
13
SPFieldLookupValueCollection values = new SPFieldLookupValueCollection();

                 foreach (Element a in List<Element>)
                    {
                        SPListItemCollection lookupItem = // query List to get relevant Items, Or Query ID's directly
                        if (lookupItem != null && lookupItem.Count > 0)
                        {
                            values.Add(new SPFieldLookupValue(lookupItem[0].ID, string.Empty));
                        }

                    item["LookUpField"] = values;
                    item.SystemUpdate();
                    }

How to set the Edit Form for a ContentType

Here is some code, that demonstrates how to set your custom Edit-Form to a ContentType programmatically .
The Edit Form is (just for example) deployed within the Layouts Folder:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
                SPContentType type = null;
                try
                {
                    type = rootweb.ContentTypes[cttypeconfig.Title.GetValue()];
                }
                catch (Exception ex) { Log.WriteError( "Error Accessing CT's", ex.ToString()); }

                if (type != null)
                {
                    if (cttypeconfig.CustomForm.UseCustomForm)
                    {
                        type.EditFormUrl = "/_layouts/QM/EditForm.aspx";
                        type.NewFormUrl =  "/_layouts/QM/EditForm.aspx";
                        type.DisplayFormUrl =  "/_layouts/QM/EditForm.aspx";
                        type.XmlDocuments.Delete("http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url");
                        type.Update();
                    }

How to set Group Fields / Multi User in SharePoint Programmatically

Here is the way how to set Group Fields and MultiUser in SharePoint programmatically:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Create a List of Groups
List<SPGroup>  groups = new List SPGroup(5);

//Try to acsess Groups get groups etc..
SPGroup group = null;  
try  
{  
    group = rootweb.SiteGroups[groupkey];
}
 catch (Exception ex)
{
//log
 return;
}
   
if (group != null)
{  
    groups.Add(group);
}

string allgroups = string.Empty;  

foreach (SPGroup sgroup in groups)  
{  
    allgroups = allgroups+= sgroup.ID.ToString() + ";#"+ sgroup.LoginName.ToString() + ";#";
}  
 rootweb.AllowUnsafeUpdates = true;  
 item[groupfield] = allgroups;  
 item.Update();

Telerik Framework: RadGrid–out of the box export to excel

The decision of make or buy should  always be a matter before starting with
development of standard or individual software. On the one hand foreign frameworks
enable you to decrease development costs on the other hand you are often
unable to change the code of the foreign framework classes directly or if you do so your
changes are not fully compatible with the updates of the framework supplier.

Further within the web-context (for example within the SharePoint-context) it is
impossible to use or support different framework versions (reg. precompiling and same
namespaces. To be safe, you always have to support the newest framework
version, that can be a hard job if the versions change daily :) .

One of the most powerful web-ui frameworks is the telerik framework with a continuous release cycle (each quarter). This framework fits nearly 100% of your wishes, like exporting data in exel-workbooks out of a grid view.

Example:

image

You’ll find further infos here:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx

The telerik RadGrid is able to perform pdf, excel and word export out of the box. Take a look !

How to create an excel file from a Data-Table with c# .net

There is no out of the box solution for this problem. Fist you need a good Libary
who ist able to do the transformation. You find a good one here:

the following code shows you how to do the final transformation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private  void CreatingWorkbook(DataTable finaltable)
{
string file = this._filenameSaveDirectory+"\\example.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("example");
int columnindex = 0;
foreach (DataColumn dc in finaltable.Columns)
{
int rowindex = 0;
worksheet.Cells[rowindex, columnindex] = new Cell(columnindex + 1);
foreach (DataRow dr in finaltable.Rows)
{
worksheet.Cells[rowindex + 1, columnindex] = new Cell(dr[columnindex].ToString());
rowindex++;
}
columnindex++;
}
workbook.Worksheets.Add(worksheet);
if (File.Exists(file))
{
File.Delete(file);
}
workbook.Save(file);
}

How to save / read Custom objects into/from a .xml file

Here is the way how to serialize / deserialize custom objects into
a xml file within the application directory. c# .net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Config
{
      //define object properties here

    public static Config ReadConfig()
    {
         string path = Application.StartupPath+"\\config.xml";
         if (File.Exists(path))
        {
           XmlSerializer ser = new XmlSerializer(typeof(Config));
           using (StreamReader sr = new StreamReader(path))
           {
             Config config = (Config)ser.Deserialize(sr);
             return config;
           }
       }
      return null;
    }
   
   public static void SaveConfig(Config config)
   {
     string path = Application.StartupPath + "\\config.xml";
     XmlSerializer ser = new XmlSerializer(typeof(Config));
     using (FileStream str = new FileStream(path, FileMode.Create))
    {
         ser.Serialize(str, config);
    }
  }
}

SharePoint 2007 document-library webpart and ajax

We had problems with the standard document –  library webpart and asynchronous ajax
calls within the same page. The problem occurs when the view of the document library has grouping included.
The grouped and expanded nodes are cached in the webpart. The WebPart restores the expanded
nodes on the next postback. This restore procedure is a asynchronous java script call.


image

This script call is made for each grouped and expanded node. During the asynchronous call the global script variable
g_ExpGroupInProgress is set to true. After the callback has finished, this variable is set back to false, and then the
next call ( for the next node) can proceed. During a parallel asyncronous ajax / script – callback postback in an
Update-Panel on the Page the SharePoint callback is gone, and the global script variable will not be set back to true.

We had this Problem with a Java- Script Timer, that initializes a loading prodecure for a control included in
an updatepanel ( Load after first page Load)
To prevent this, include the following code snippet in your java script :


image

How to disable line break in Telerik Controls

Just for reminder, how to disable line break in the Radgrid and for Toolbar Buttons

1) for Toolbar Buttons : Create Style Sheet with the white-space attribute

for Example:

<style type=”text/css”>
.NoWrapClass
{
white-space: nowrap;
}
</style>

Set the CssClass Property of the Control with the Value of your CssClass.

2) To disable the line break for the RadGrid Columns, you have first to create your own Skin, because the Telerik Style’s are deeply inherited by these skins. The recommended way to change the Style is to create your own skin, and change the Styles, that can’t be set with the Skin editor, manually.

You can find the Style Builder here: Telerik Visual Style Builder

Editing Skins general information information to Skins

The displayed Style needs to be changed at the level where the table cells / controls are attributed. You can Read the following links for further Information: Understand the Skin CSS and CSS Skin File Selectors.

At least, to prevent the Column line-break you have change the following css-classes :

.RadGrid_ecspand .rgHeader,

.RadGrid_ecspand th.rgResizeCol

{

…….

white-space: nowrap;

}

LINQ Part II Easy Sorting

With Linq you can easy create Sorting Delegates
Instead of writing the delegates the old way :

1
  pers.Sort(delegate(Person p1, Person p2) { return p1.Name.CompareTo(p2.Name); });

You can also write it with Linq this way:

1
   pers.Sort((o1, o2) => o1.Name.CompareTo(o2.Name));

It is Easier to use and to remember,and its also written faster.
There is no argument left for not using this, even its as fast as the old way:
(you can download the dem and check it for your self)

This is the Person Class for reference
you can also download the sample:
LinqExample

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Person
{

public int Age { get; set; }
public string ForeName { get; set; }
public string Name { get; set; }
public Person(string Forename, string Name, int Age)
{
this.ForeName = Forename;
this.Age = Age;
this.Name = Name;
}
}
Get Adobe Flash playerPlugin by wpburn.com wordpress themes