How To Get The Text Value Rather Than The HTML Value Of A MultiLine ListItem Using SharePoint Client Object Model



TODO:

You have a multi-line field in a list.  When you get the value, it comes back as HTML when you reference it as item["field"].  To get the text, rather than the HTML, you need to do the following.

 

SOLUTION:

//put at top!!!
using SP = Microsoft.SharePoint.Client;
 
//put inside class !!! 
SP.ListItem targetItem = null;
//todo, set your targetItem = to the item you want.
 
using(ClientContext clientContext = new ClientContext("http://your.url.goes.here"))
{
     var itemFieldValues = targetItem.FieldValuesAsText;
     clientContext.Load(itemFieldValues);
     clientContext.ExecuteQuery();
}
string fieldTextValue = itemFieldValues["My item Title"];

 

NOTES:

There are no notes on this topic.

How To Use Excel.Application.GetSaveAsFilename() Method



TODO:

Have you ever wanted to use the Excel.Application.GetSaveAsFilename method to save your files?


SOLUTION:

Excel.Application excel = new Excel.Application();

FileInfo fileInfo = new FileInfo(txtInputFile.Text.Trim());

//so show the save as, and then filter by current extension only....reason is, that SaveAs() will save in current format, so format changes cannot happen here.
object fileName = excel.GetSaveAsFilename(fileInfo.Name, string.Format("Excel files (*{0}), *{0}", fileInfo.Extension), 1, "Save File Location");

 

NOTES:

This example will display the Save As dialog box.  I limit the box to the current file type, as calling excel.SaveAs(filename) will not change the file type.

How To Fix A Missing Local Publishing Profile Visual Studio 2012



TODO:

Have you lost the ability to publish your website locally?  If so, then you lost your profile for local publishing.

 

SOLUTION:

The second post on this link, has a correct solution.  Basically you need to add a new profile, choose File System as the type, and select a valid location.

 

NOTES:

There are no notes on this topic.

How To Add A Custom Pre-Requisite To A Click-Once Application



TODO:

Have you ever wanted to add your own prerequisites to a Click-Once application?

 

SOLUTION:

1.  Follow the instructions here to create a package manifest.

2.  Follow the instructions here to create a product manifest.

3.  Last restart Visual Studio and you will see your prerequisites in the list.

 

NOTES:

There are no notes on this topic.

How To Truncate a Decimal To X Places



TODO:

Have you ever wanted to truncate a decimal to X places?

 

SOLUTION:

decimal rate = .07654;
decimal newRate = Math.Truncate(rate * 1000m) / 1000m;

 

NOTES:

The result will be .076

How To Fix "Unable to update the entityset because it has a defining query and no UpdateFunction element exists in the ModificationFunctionMapping element to support the current operation" Error



TODO:

You try to insert a record using the Entity Framework and get the following error:

"Unable to update the entityset because it has a defining query and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation"

 

SOLUTION:

Add a primary key to the table.  Also make sure the Concurrency Mode of the Primary Key is set to "Fixed" (right click column, choose properties)

 

NOTES:

There are no notes on this topic.

How To Insert A Record Using The Entity Framework And Get Back The Identity Of the Record



TODO:

Have you ever wanted to use the Entity Framework to insert a new record into the database, and get back the identity associated with it?

 

SOLUTION:

using(DataEntities dataEntities = new DataEntities())
{
       FormNumber formNumber = new FormNumber();
       dataEntities.AddToFormNumbers(formNumber);
       dataEntities.SaveChanges();
       return formNumber.Id;
}

 

NOTES:

This assumes you have an EDMX created called "DataEntities".  It assumes you have a table called "FormNumber", with an Identity column called "Id".

How To Find A String And Replace It With Another String Using C#



TODO:

Have you ever wanted to replace a string that exists in another string?

 

SOLUTION:

string foo = "123456-7890-abcd";
string bar = foo.Replace("-", "");

 

NOTES:

The example above will replace '-' with an empty string.  The result will be 1234567890abcd.

How To Remove The Last X Characters From A String Using C#



TODO:

Have you ever wanted to remove the last X characters from a string in C#?

 

SOLUTION:

string foo = "1234567890abcd";
string bar = foo.Substring(foo.Length - 4);

 

NOTES:

The example above will remove the last 4 characters from foo, and store the result in bar.

How To Throttle How Many Message Are Pulled From MSMQ



TODO:

You have an MSMQ that is wired to a WCF service.  You want to throttle how many messages are processed, so that you can better control the system resources.  To do so, you need to change the config file for your WCF...and add the following entries.

 

SOLUTION:

<behaviors>
 <serviceBehaviors>
  <behavior name="DefaultThrottlingBehavior">
   <serviceThrottling maxConcurrentCalls="jQuery15207601982052437961_1377884886132?"
          maxConcurrentSessions="???"
          maxConcurrentInstances="???" />
  </behavior>
 </serviceBehaviors>
</behaviors>

 

NOTES:

Replace the ??? with the values you want.  It may take some trial and error to see what settings work best.