كيفية تنزيل صفحة SharePoint ASPX من الخادم باستخدام PowerShell

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/56664

  •  10-12-2019
  •  | 
  •  

سؤال

قمت بإجراء بعض التغييرات في صفحات SP ASPX في بيئة.أريد نقل هذه التغييرات إلى TFS الخاص بي.عادة ما يأخذ المرء الصفحات باستخدام مصمم، وحفظه إلى سطح المكتب، وحفظ ذلك إلى TFS.

ولكن هل هناك طريقة PowerShell لأتمتة هذا؟- يعني فقط توفير صفحات ASPX المطلوبة إلى نظام الملفات

هل كانت مفيدة؟

المحلول

I believe this is what you are looking for. You can export a specific file or object from the Export-SPWeb context, not the whole kitten kaboodle.

Export-SPWeb -identity "http://sharepoint" -ItemUrl "/default.aspx"  -Path "c:\default.aspx" 

Import-SPWeb -identity "http://sharepoint" -Path "C:\default.aspx" 

نصائح أخرى

As I understood you need source of the file from content DB to check it into Source Control. Please, try the following code:

Add-PSSnapin Microsoft.Sharepoint.Powershell
$web = Get-SPWeb <path to web>
$file = $web.GetFile('<relative path to file>');
$bytes = $file.OpenBinary();
[System.IO.File]::WriteAllBytes('<path to file on your disk>', $bytes);

you should use WebRequest

$web = Get-SPWeb $webUrl
$path = "C:\file.aspx"

$request = [System.Net.WebRequest]::Create($url)
$request.UseDefaultCredentials = $true

#do web request - if exception -> item does not exist
try {
    $response = [System.Net.WebResponse]$request.GetResponse();
    if ($response.StatusCode -ne "OK") {
        write-host "Error: " $response.StatusCode;
        return;
    }

    # get contents
    $stream = [System.IO.Stream]$response.GetResponseStream();
    $streamReader = New-Object System.IO.StreamReader($stream);

    $data = $streamReader.ReadToEnd();

    $enc = [system.Text.Encoding]::UTF8
    $filebytes = $enc.GetBytes($data) 

    $stream.Close();    
    $streamReader.Close();

    # save file        
    [System.IO.File]::WriteAllBytes($Path, $filebytes)
}
catch [Exception]
{
    write-host "exception" $error[0]
}

$web.Dispose() 

EDIT: I was in good mood so I've completed also the code to download contents and save them to file system.

Another approach is possible :

$web = get-spweb http://server/yoursite
$file = $web.GetFile("$($web.Url)/pages/home.aspx")
[System.IO.File]::WriteAllBytes("$(gl)\$($file.Name)", $file.OpenBinary())

This will write in the current directory the content of the file "Pages/home.aspx"

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top