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 Remove An Image From The Header Text Of A RadGrid Column



TODO:

Have you ever wanted to remove an image from the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
protected void RemoveGridHeaderImage(RadGrid TargetGrid, string HeaderText)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     try
     {
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.  You can use this in conjunction with adding an image to a RadGrid Header at this link, which will allow you to toggle the image on and off depending on the contents of the grid.

How To Add An Image To The Header Text Of a RadGrid Column



TODO:

Have you ever wanted to add an image to the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
/// <param name="ImageUrl"></param>
protected void AddGridHeaderImage(RadGrid TargetGrid, string HeaderText, string ImageUrl)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     Image img = new Image();
     Literal space = new Literal();
     space.Text = " ";
     try
     {
          img.ImageUrl = ImageUrl;
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
     finally
     {
          img.Dispose();
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.