Category: .net

This c# code can connect sharepoint 2013 through restful by username and password

Thanks God, This c# code can connect sharepoint 2013 through restful by username and password

            HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("http://win-344c6v6tjp4:88/_api/web/lists");

            endpointRequest.Method = "GET";
            endpointRequest.Accept = "application/json;odata=verbose";
            NetworkCredential cred = new System.Net.NetworkCredential("administrator", "this is my password");
            endpointRequest.Credentials = cred;
            HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
                WebResponse webResponse = endpointRequest.GetResponse();
                Stream webStream = webResponse.GetResponseStream();
                StreamReader responseReader = new StreamReader(webStream);
                string response = responseReader.ReadToEnd();
                JObject jobj = JObject.Parse(response);
                JArray jarr = (JArray)jobj["d"]["results"];
                foreach (JObject j in jarr)
                    Console.WriteLine(j["Title"] + " " + j["Body"]);

            catch (Exception e)
                Console.Out.WriteLine(e.Message); Console.ReadLine();

read count : 17

Powershell commands to upload/download a page to sharepoint 2013

Upload file:

Add-PSSnapIn "Microsoft.SharePoint.Powershell" 
# Set the variables 
$WebURL = “http://your_sharepoint/your_site” 
$DocLibName = "Pages"
$FilePath = “C:\a.aspx” 

# Get a variable that points to the folder 
$Web = Get-SPWeb $WebURL 

$List = $Web.GetFolder($DocLibName) 
$Files = $List.Files 

# Get just the name of the file from the whole path 
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) 

# Load the file into a variable 
$File= Get-ChildItem $FilePath

# Upload it to SharePoint 
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) 

Download file (Html special characters will be escaped):

Add-PSSnapin Microsoft.Sharepoint.Powershell

$WebURL = “http://kmp21dev.emsd.hksarg/kmp21dev” 
$web = Get-SPWeb $WebURL
$file = $web.GetFile('pages/homepage.aspx');
$bytes = $file.OpenBinary();

[System.IO.File]::WriteAllBytes('c:\users\spadmin\homepage.aspx', $bytes);

read count : 10

Sharepoint online bug

Sharepoint online bug – If you place an html-email-address to it and click “check” button, it crash. Even you delete all text and the check button can’t resume normal.

Sharepoint online bug
Sharepoint online bug

read count : 223

command to connect sharepoint 2013 to office web apps server

First, do these in office web apps server

new-officewebappsfarm -Verbose -InternalURL -ExternalURL -AllowHTTP -ClipartEnabled -TranslationEnabled -EditingEnabled
new-officewebappsfarm -Verbose -InternalURL -ExternalURL -AllowHTTP -ClipartEnabled -TranslationEnabled -EditingEnabled

Second, do these in sharepoint server

Remove-SPWOPIBinding -All:$true
New-SPWOPIBinding -ServerName  -AllowHTTP

read count : 301