Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Wednesday, August 7, 2013

Visual Studio hotkey for formatting XML: Ctrl+k+f

There will inevitably come a time when you're going to obtain some XML output that you need to review that would, in all honesty, be impossible to read without proper formatting.  A good example would be this response from the the YouTube API that provides a list of videos that a specified user has uploaded (i.e. which would appear as follows in Notepad):




In many cases, simply copying and pasting the XML it into Visual Studio might work, but, in the off chance it doesn't, you might get something like this.




If that happens, simply hit Ctrl+k+f and the XML will be displayed in an easy-to-read format:



Wednesday, October 24, 2012

Adding a custom CSS file to your Visual Web Part

If you would like to add a custom CSS file to a Visual Web Part that allows the styling of the web part to remain consistent no matter where it's installed, you can do so via the following steps:

  1. Using Visual Studio 2010, open your Visual Web Part solution
  2. In Solution Explorer, right-click on the project and select Add -> SharePoint "Layouts" Mapped Folder
  3. Right-click on the newly created Layouts folder and select Add -> New Folder
  4. Edit the name from "NewFolder1" to "1033"
  5. Right-click on the "1033" folder and select Add -> New Folder
  6. Edit the name from "NewFolder1" to "Styles"
  7. Right-click on the "Styles" folder and select Add -> New Folder
  8. Edit the name from "NewFolder1" to the name of your Project (i.e. MyProject in this example)
  9. Right-click on the "MyProject" folder and select Add -> New Item...
  10. Under the Installed Templates section, expand Visual C# and click on Web
  11. Click on the Style Sheet icon, update the name of your style sheet (i.e. Standard.css in this example), and click Add
  12. You may now enter the appropriate style sheet rules in this file and save the changes
During the deployment of your Visual Web Part, the custom style sheet will be deployed directly to the SharePoint farm under the following location on the web front end servers:  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES\MyProject.

Now, to reference the style sheet in your Visual Web Part, you may do so via the following steps:
  1. Open your Visual Web Parts .ascx file
  2. After the "<%@ Control" tag, add the following line:  <SharePoint:CssLink ID="cssLink1" runat="server" DefaultUrl="MyProject/Standard.css" />
  3. Save the change
At this point, you will be able to reference the new style sheet within the controls on your .ascx page.

Thursday, August 30, 2012

Adding the contents of an entire folder into a Visual Studio 2010 project

If you'd like to bulk add the contents of an entire folder into the structure of a Visual Studio 2010 project (i.e. JQuery libraries are a perfect example), you'll soon discover that the Add -> Existing Item... route is not the way you want to go.  A quick solution for bulk adding a folder is to do the following actions:

  1. Open Windows Explorer and navigate to the folder you wish to copy
  2. Right-click on the folder and select Copy
  3. Open the applicable Visual Studio 2010 solution
  4. Select the project you wish to copy the folder to
  5. Navigate to the proper location in the project and right-click on the parent location of the folder
  6. Select Paste
The folder and all of it's sub-folders and files will now be copied into the specified location.  I know this seems like it would be obvious, but I seem to experience a moment of "how did I do that last time?" whenever it's been a while since I've created a solution that requires me to do this.  Good stuff!

Friday, March 9, 2012

Your solution file isn't being displayed in the Visual Studio 2010 Solution Explorer

In it's default state, Visual Studio 2010 isn't configured to display the solution in the Solution Explorer window.  If you wish to change the configuration to always display the solution, you can do so via the following steps:
  1. Open Visual Studio 2010
  2. Click on Tools -> Options
  3. Expand the Project and Solutions node
  4. Click on General
  5. Place a check in the Always Show Solution checkbox
  6. Click OK