Monthly Archives: June 2014

Windows – Installation from Harddrive

Hello everyone. Today I found a method to install Windows directly from a hard drive.

To do so you need to do the following:

  • Get a hard drive you want to install into your machine (I chose a 64GB SSD)
  • Format it and choose NTFS as file system

setup_windows_harddrive_hdd

After you prepared your hard drive you need to copy the following folders and files from your Setup Medium to your hard drive:

  • boot
  • sources
  • bootmgr

setup_windows_harddrive_setup_files

Now run cmd as Administrator and run the following commands to make your hard drive bootable:

diskpart
list disk
select disk x
list partition
select partition x
active
exit
X:\boot\bootsect.exe /nt60 X:

Replace x and X with the values of your hard drive.

setup_windows_harddrive_cmd_bootsect

That´s it. Your preparations are done. Now insert the hard drive into your machine and make sure to boot from hard drive.

Install Windows as you would do normally but do not format your hard drive, otherwise all setup files would get lost and the setup will not finish successfully.

After Windows has been installed successfully, run cmd as Administrator and run the following command:

msconfig

setup_windows_harddrive_msconfig_boot

This will open a window like the one in the screenshot above. Now choose the Boot tab and select Windows Setup (\windows) and delete it. This will remove the Windows Setup option from the Boot Manager window when you boot your machine.

setup_windows_harddrive_delete_sources

The last step is to remove the setup files. To do so, delete the sources folder from the C partition of the machine.

That´s it. You successfully installed Windows without using any CDs/DVDs or USB Sticks or additional software. For more information have a look at the sources.

Sources:

http://www.instructables.com/id/Install-Windows-7-without-USB-or-DVD-without-upgra/

http://www.instructables.com/id/How-to-CLEAN-Install-Windows-8-directly-from-Hard-/

Tagged

C# – Convert DOC to DOCX

Hello everyone. Today I tried to figure out how I can convert doc files to docx files by using C#. Well, and I came up with the below example.

The prerequisites for this solution are:

  • Visual Studio
  • Microsoft Office installed on the machine where you want to run this application

Now I will explain the necessary steps.

The first thing you need to do is to add a reference by clicking on Add Reference…

visual_studio_doc_to_docx_add_reference

Now search for Microsoft Word 14.0 Object Library (The version number 14 represents Microsoft Office 2010. Version number 15.0 represents Microsoft Office 2013) and click OK.

visual_studio_doc_to_docx_microsoft_word_object_library

Important: Make sure you have a version of Microsoft Office installed on your Development machine. Otherwise you will not find the reference you need.

Now for the code. Here you go:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DOCToDOCX
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void browse_Click(object sender, EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
pathTextBox.Text = openFileDialog1.FileName;
}
}

private void convert_Click(object sender, EventArgs e)
{
Function f = new Function();

f.ConvertDOCToDOCX(pathTextBox.Text);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.IO;

namespace DOCToDOCX
{
class Function
{
public void ConvertDOCToDOCX(string path)
{
Application word = new Application();

if(path.ToLower().EndsWith(".doc"))
{
var sourceFile = new FileInfo(path);
var doc = word.Documents.Open(sourceFile.FullName);

string newFileName = sourceFile.FullName.Replace(".doc", ".docx");
doc.SaveAs2(FileName: newFileName, FileFormat: WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2010);

word.ActiveDocument.Close();
word.Quit();
}
}
}
}

Important: If you remove the following line of code from the above code your documents will stay in Compatibility Mode after they were converted to docx files.

CompatibilityMode: Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2010

That´s it. Pretty simple, right? Hopefully my post was interesting for you. And as always you can download my code from here.

Sources:

http://justgeeks.blogspot.co.at/2011/09/convert-batch-of-doc-files-to-docx.html

http://msdn.microsoft.com/en-us/library/15s06t57.aspx

http://row5is.wordpress.com/2012/07/06/convert-doc-to-docx-using-powershell/

http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.saveas2.aspx

Tagged

C# – Create DOCX from HTML code

Hello everyone. Today I was playing around to find out how to convert HTML code to Word documents (.docx). I think I found a very simple solution to do this. All you need is Visual Studio and a dll you can download from here.

For my example I created a new Windows Forms Application.

DOCXToHTML_project

The next step is to add a reference to the dll “HTMLtoDOCX.dll”.

DOCXToHTML_reference_dll

Now here is the code I used for my example application:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CreateDOCXFromHTML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void browse_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Save file as...";
saveFileDialog1.Filter = "Word Document (*.docx)|*.docx|All files (*.*)|*.*";
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
path.Text = saveFileDialog1.FileName;
}
}

private void save_Click(object sender, EventArgs e)
{
Function f = new Function();
string data = f.GetHTMLfromUrl(url.Text);

NoInkSoftware.HTMLtoDOCX NewFile = new NoInkSoftware.HTMLtoDOCX();
NewFile.CreateFileFromHTML(data, path.Text);

MessageBox.Show("Save to DOCX finished.");
url.Text = "";
path.Text = "";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace CreateDOCXFromHTML
{
class Function
{
public string GetHTMLfromUrl(string Url)
{
string data = string.Empty;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (response.CharacterSet == null)
readStream = new StreamReader(receiveStream);
else
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
data = readStream.ReadToEnd();
response.Close();
readStream.Close();
}

return data;
}
}
}

My example application needs the following input to work:

Here is an example document I created from my previous post:

DOCXToHTML_finished_docx

As you can see the result is not perfect but still very good. I hope my post was useful and interesting for you 🙂

And as always you can download my example from here.

Important: I did not create this solution on my own. I got the code from here. Please give this guy some credit for his great work.

Sources:

http://www.codeproject.com/Articles/91894/HTML-as-a-Source-for-a-DOCX-File

http://stackoverflow.com/questions/16642196/get-html-code-from-a-website-c-sharp

http://www.csharpdeveloping.net/Snippet/How_to_create_file_save_dialog

Tagged

SharePoint – Use Delegate Control to deploy scripts to all pages

Hello everyone. Recently I was searching for an easy way to add scripts to all pages in a SharePoint Site Collection. Mostly because I wanted to find an easy way to add jQuery and SPServices to the pages where I need them with an easy way to deploy new versions and without editing the Master Page of my SharePoint websites. And I think I found a good solution called SharePoint Delegate Control. All you need for this solution is Visual Studio installed on a SharePoint Development Server and you are ready to go.

The first step is to open up Visual Studio to create a new project.

visual_studio_2010_start

Now create a new Empty SharePoint Project.

visual_studio_2010_empty_sharepoint_project

Choose Deploy as a farm solution for your project. This way your solution will be deployed in your entire farm and you can use it in every Web Application when you need it.

visual_studio_deploy_farm_solution

Now we need to add some new items to our project.

visual_studio_2010_add_new_item

First create a new User Control item. I called mine “jQueryAndSPServicesControl.ascx”.

visual_studio_2010_add_user_control

Next create a new Empty Element. I called mine “Elements.xml”.

visual_studio_2010_add_empty_element

Next step: Map SharePoint “Layouts” folder to your project to store your scripts.

visual_studio_2010_add_layouts_folder

Here is an example structure of the Layouts folder from my project:

sharepoint_layouts_folder_structure

Store your scripts by pasting them into your folder structure.

Now we will add our scripts into our User Control.

visual_studio_2010_user_control_custom_scripts

Here is the code from my “jQueryAndSPServicesControl.ascx” User Control:

...
<script type="text/javascript" src="/_layouts/AddSPServicesSolution/jQuery/jQuery.min.js"></script>
<script type="text/javascript" src="/_layouts/AddSPServicesSolution/jQuery.SPServices/jQuery.SPServices.js"></script>
<script type="text/javascript" src="/_layouts/AddSPServicesSolution/jQuery.SPServices/jQuery.SPServices.min.js"></script>

Now we need to add our User Control to our Elements.xml file.

visual_studio_2010_elements_custom

Here is the code from my “Elements.xml” XML file:

<?xml version="1.0" encoding="UTF-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control ControlSrc="~/_CONTROLTEMPLATES/AddSPServicesSolution/jQueryAndSPServicesControl.ascx" Sequence="90" Id="AdditionalPageHead"/>
</Elements>

After that you need to configure your feature settings. Enter a Title and a Description for your feature and choose a Scope. I chose Site since I wanted my feature to deploy my scripts in the entire Site Collection when I activate it.

visual_studio_2010_feature_scope

After you finished all of the above steps you are ready to go. Start the Debug process to deploy your solution to test it.

When you have a look at your Site Collection features (when you chose Site as a Scope for your feature like I did) you will see that your feature is listed and activated.

sharepoint_site_collection_features_custom

Now go to a page in your SharePoint Site Collection and have a look at its source code. You will see that your scripts have been successfully added to your pages source code. (If you retract your solution, for example by stopping the Debug process, your scripts will be retracted from your pages as well.)

sharepoint_page_source_active_feature

I used an example script to show you what happens when you activate and deactivate your solution in your Site Collection.

Here is the code of my example script:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "City",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
$("#tasksUL").append(liHtml);
});
}
});
});
</script>
<ul id="tasksUL"/>

My example script will simply get all items from a List called “City” and display them as a Bulleted List.

The below screenshot shows what my script will do when our custom feature is activated.

sharepoint_delegate_control_feature_activated

The next screenshot shows what happens when you deactivate our custom feature.

sharepoint_delegate_control_feature_deactivated

As you can see nothing bad happens to your page or Site Collection. Your scripts will just stop working.

That´s it. Like that you can deploy your own scripts to your Site Collections in a pretty simple manner. I hope you liked my post and I hope it was useful for you. If you liked my post and want the source code you can download my project from here.

Sources:

http://www.jbmurphy.com/2012/07/03/how-to-add-custom-javascript-code-to-all-sharepoint-2010-pages-delegatecontrol/

http://howtosharepoint.blogspot.co.at/2009/11/include-jquery-file-to-sharepoint.html

http://styledpoint.com/blog/inject-your-jquery-javascript-into-sharepoint-2010-without-modifying-any-master-page-page-layout-or-using-a-web-part/

http://blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate-controls.aspx

http://spservices.codeplex.com/wikipage?title=GetListItems

Tagged ,

SharePoint – Use PowerShell to copy Library items and column data to another Library

Hello everyone. A few days ago a colleague asked me if there is a quick way to copy Library items and column data to another Library. The reason he asked was because he wanted to create a new website to replace his old one which would satisfy the needs of his users better and he needed all the data stored in that Document Library. This Library contained about 2000 items so he asked me for help since moving them manually would be a real pain. I found some great posts online and came up with a PowerShell script as solution for his problem.

Here is my script:


Param([parameter(Mandatory=$true)][alias("SourceWebUrl")]$SPSourceWebUrl, [parameter(Mandatory=$true)][alias("SourceListName")]$SPSourceListName, [parameter(Mandatory=$true)][alias("DestinationWebUrl")]$SPDestinationWebUrl, [parameter(Mandatory=$true)][alias("DestinationListName")]$SPDestinationListName)

#Add SharePoint PowerShell SnapIn if not already added
if((Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

#Get data of SharePoint Source List
$SPSourceWeb = Get-SPWeb $SPSourceWebUrl
$SPSourceList = $SPSourceWeb.Lists["$SPSourceListName"]
$SPSourceListColumns = $SPSourceList.Fields
$SPSourceListItems = $SPSourceList.Items

#Get data of SharePoint Destination List
$SPDestinationWeb = Get-SPWeb $SPDestinationWebUrl
$SPDestinationList = $SPDestinationWeb.Lists["$SPDestinationListName"]

#Iterate through all SharePoint List items of Source
foreach($SPSourceListItem in $SPSourceListItems)
{
#Copy data from Source and create a new item in Destination
$SPNewListItem = $SPDestinationList.RootFolder.Files.Add($SPSourceListItem.Name, $SPSourceListItem.File.OpenBinary()).Item;;

#Iterate through each column in Source
foreach($SPSourceListColumn in $SPSourceListColumns)
{
#Ignore Read only fields like Created, Modified, etc.
if($SPSourceListColumn.ReadOnlyField -ne $True)
{
#Copy column data from Source to Destination
$SPNewListItem[$($SPSourceListColumn.InternalName)] = $SPSourceListItem[$($SPSourceListColumn.InternalName)];
}
}
#Update current item
$SPNewListItem.Update();
}

The script will do the following:

It will gather all data from the Source Library and create new items in the Destination List. After that the script will update the new items with the column data from the Source Library. The script will ignore Read only fields like Created, Modified, etc.

Important:

Please keep the following things in mind when you run this script:

  • The script will only copy the latest version of the items. For example: Only the latest Draft or Published Version. All previous versions will not be copied to the Destination Library. (This wasn´t a problem for me since my colleague did not need the old versions.)
  • If some columns do not exist at the Destination they will simply be ignored. You will not receive errors or notifications.
  • You need to run this script on a server of your SharePoint Farm and need to use an account with appropriate permissions. Otherwise you will not be able to run it. It is also important to know that the column values for the fields Created by and Modified by will be set to this account. This means you will lose the information who created or modified items when you copy them using this script.

As always you can get my script from here.

That´s it. I hope my post was useful for you.

Sources:

http://myspworld.wordpress.com/2012/06/21/copying-files-between-document-libraries/

http://letitknow.wordpress.com/2011/03/17/100/

http://www.sharepointed.com/2011/06/17/copy-files-to-another-document-library-maintain-metadata/

Tagged ,

SharePoint – Create your own Slider Webpart

Hello everyone. A while ago I tried to find a way to create a Slider Webpart. Something that would just slide through a bunch of Pictures containing some messages or news or something like that. And I found a solution.

To create your own Slider Webpart you need the following things:

When you have downloaded these Scripts we can create the Slider Webpart.

For my example I created a Picture Library called “Picture” to store my Pictures I want to use for my Slider Webpart. (I used some banner pictures I found online.)

sharepoint_slider_webpart_picture_Library

The next step was to create a Custom List called “Slider” containing a Multiple lines of text column called “HTML”. Use the “HTML” column to add some messages to your pictures of your Slider. (For my example I just entered a few empty lines because this determines the height of the picture on your Slider Webpart. If you don´t enter something you won´t be able to see your pictures in your Slider. If you add to much text to the HTML column your picture will be repeated.)

sharepoint_slider_webpart_slider_list

The next step was to create a Document Library called “Script” to store all the Scripts I mentioned above.

sharepoint_slider_webpart_script_library

As you saw in the above screenshot you also need a script called “SPSlider.js”. This script will actually create your Slider Webpart. Here is the code:


<script type="text/javascript" src="/sites/test2/Script/jquery.min.js"></script>
<script type="text/javascript" src="/sites/test2/Script/jquery.SPServices.min.js"></script>
<script type="text/javascript" src="/sites/test2/Script/unslider.min.js"></script>

<style type="text/css">
.hillbillyBanner { position: relative; overflow: auto; }
.hillbillyBanner li { list-style: none; }
.hillbillyBanner ul li { float: left; }
.hillbillyBanner ul {margin-left: -40px;}
</style>

<script type="text/javascript">
jQuery(document).ready(function($) {
var sliderList = "Slider"; // Name of the list that contains slides
var slideContentField = "HTML"; //Name of the Rich text field that has slide content
var slideBackgroundImageField = "Picture"; //Name of the picture field to use as background image
HillbillySlider(sliderList,slideContentField,slideBackgroundImageField);
});
function HillbillySlider(sliderList,slideContentField,slideBackgroundImageField) {
//query to retrieve all items
var query = "<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Number'></Value></Neq></Where></Query>";
//return fields for slide content and background picture
var camlViewFields = "<ViewFields><FieldRef Name='"+slideContentField+"' /><FieldRef Name='"+slideBackgroundImageField+"' /></ViewFields>";
$().SPServices({
operation: "GetListItems",
async: true,
listName: sliderList,
CAMLViewFields: camlViewFields,
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var slideContent = ($(this).attr("ows_"+slideContentField));
var picture = $(this).attr("ows_"+slideBackgroundImageField)==undefined?"":$(this).attr("ows_"+slideBackgroundImageField).split(",")[0];
//create slide (li) and append it to other slides
$("#hillbillySlider").append("<li style=\"background-image: url('"+picture +"');\">"+slideContent+"</li>");
}); // end completefunc
//start the slider
$('.hillbillyBanner').unslider();
}
}); // end SPServices call
}
</script>
<div class="hillbillyBanner"><ul id='hillbillySlider'></ul></div>

Please pay attention to the variables listed below. You need to adjust them for your environment.

var sliderList = "<Your-Slider-List-Name>"; // Name of the list that contains slides
var slideContentField = "<Your-HTML-Column-Name>"; //Name of the Rich text field that has slide content
var slideBackgroundImageField = "<Your-Picture-Library-Name>"; //Name of the picture field to use as background image

sharepoint_slider_webpart_content_editor_url

The last step is to create a Content Editor Webpart and add the Url of the “SPSlider.js” script to it.

sharepoint_slider_webpart

That´s it. Your Slider Webpart is ready.

Important note: I did not create this script. I just discovered it. Have a look at the Sources for more information.

You can download the script I used for my example from here.

Sources:

http://summit7systems.com/a-simple-jquery-content-slider-for-sharepoint-200720102013-and-o365/

http://unslider.com/unslider.min.js

Tagged ,

SharePoint – Query List items from External Lists (with jQuery and SPServices)

Hello everyone. Today I tried to find out if it is possible to query External Lists by using jQuery and SPServices so that I can use the gathered data as I wish. And I found out that it is possible. And I´m going to show you how I did it.

The screenshot below shows you that I used the data gathered from an External List to display it in a Content Editor Webpart:

sharepoint_external_list_content_editor_finished

In my example I used an External List called “Location” which I created by importing a SQL Database Table by using the Business Connectivity Services (BCS) and SharePoint Designer with the following columns:

  • Name
  • Address
  • ZIP
  • Country
  • Country_Code

(I will explain how to configure External Lists in a future post if I have the time.)

sharepoint_external_list_example_location

To store my script and the jQuery and SPServices scripts I created a Document Library called “Script”.

sharepoint_external_list_script_library

Here is the GetListItems.js script which will get the list items from the External List:

<script type="text/javascript" src="/sites/test/Script/jquery.min.js"></script>
<script type="text/javascript" src="/sites/test/Script/jquery.SPServices.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Location",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='Country_Code' /><Value Type='Text'>AT</Value></Eq></Where></Query>",
CAMLViewFields: "<ViewFields> <FieldRef Name='Name' /> <FieldRef Name='Address' /> </ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {

var liHtml = "<li>" + $(this).attr("ows_Name") + " " + $(this).attr("ows_Address") + "</li>";
$("#tasksUL").append(liHtml);

});
}
});
});

</script>
<ul id="tasksUL"/>

The script will do the following:

It will get all items from the external list, filter them by the column Country_Code and will insert them into a Bulleted List if the Country_Code is “AT”. The returned fields are “Name” and “Address”.

Important note: I only managed to insert the column data into the Bulleted List after I inserted the string “ows_” before the column name (For example: Instead of “Address” I needed to write “ows_Address”). Otherwise it did not work for me. I don´t know why, so if someone knows please let me know.

As always you can download my script from here.

In the next screenshot I added the link of my GetListItems.js script to a Content Editor Webpart.

sharepoint_external_list_content_editor_url

That´s all that needs to be done to make this script work. If you configured everything correct your result will look like the first screenshot in this post. Please keep in mind that it takes some time for External List items to load, so it might take some time before your page has finished loading.

I hope my post was helpful for you.

Sources:

http://www.itidea.nl/index.php/jquery-spservices-and-autocomplete/

http://documentation.agilepoint.com/SupportPortal/DOCS/ProductDocumentation/CurrentRelease/DocumentationLibrary/maps/agileshapeCamlQueryExample.html

https://williamwmy.wordpress.com/tag/getlistitems/

http://social.technet.microsoft.com/forums/sharepoint/en-US/f5371b48-d1aa-4907-ae08-dd7721bd42a2/external-content-type-login-failed-for-user-domainmyuser

Tagged ,