简体   繁体   English

如何更新存储在Sharepoint加载项应用程序文件中的URL?

[英]How to update url stored in Sharepoint add-in app file?

I created an High-Trust add-in for SharePoint 2013 with custom ribbon action and custom menu action. 我使用自定义功能区操作和自定义菜单操作为SharePoint 2013创建了一个高信任度加载项。

For this, I have an ASP.NET MVC WebSite with the methods in the controller which match with the virtual urls put as custom action url. 为此,我有一个ASP.NET MVC网站,其控制器中的方法与作为自定义操作URL放置的虚拟URL相匹配。 So, in the different elements.xml files, I filled action urls using the token 'remoteUrl', so no problem with the mapping. 因此,在不同的elements.xml文件中,我使用标记“ remoteUrl”填充了操作url,因此映射没有问题。

When i create a package with VS2013, I write the url of my website which is on VM reachable from SP Server, and the client ID (I got from SP while registring my app). 当我使用VS2013创建一个程序包时,我写了我的网站的URL,该URL可从SP Server访问VM上,以及客户端ID(我从SP那里获取我的应用程序时从SP获取)。 When I click on 'Finish', VS2013 generates a file '.app' which can be imported in SP online store or SP internal store. 当我单击“完成”时,VS2013生成文件“ .app”,可以将其导入SP在线商店或SP内部商店。

Here is my problem, if I need to change the address of my website (which is stored in the app file, VS2013 just replaces the token 'RemoteUrl' with the url I give to it), is there any clean way to update the app file or may be if possible, directly the app stored in the SP application store (local to the server) ? 这是我的问题,如果我需要更改网站地址(存储在应用程序文件中,VS2013会用我提供的网址替换令牌“ RemoteUrl”),是否有任何干净的方法来更新应用程序文件,或者如果可能的话,直接存储在SP应用程序存储区中(服务器本地)的应用程序?

I found nothing for this problem. 我没有发现这个问题。 I saw few things about updating app with events and web services, but I didn't understood. 我没有看到有关使用事件和Web服务更新应用程序的几件事 ,但我不了解。

[EDIT] : I didn't understood that I have to change app version each time I need to update it that's why It didn't worked. [编辑]:我不知道每次需要更新应用程序版本时都必须更改应用程序版本,这就是为什么它不起作用的原因。 Also, it seems that there is no other way to update the url in app file than modifying the AppManifest.xml in app file (which is a zip). 另外,似乎除了修改应用程序文件(是zip)中的AppManifest.xml外,没有其他方法可以更新应用程序文件中的url。

In one of my projects we used to do it with the following PowerShell script. 在我的一个项目中,我们曾经使用以下PowerShell脚本来实现。 It extracted the app file (it's just a ZIP) and modified multiple nodes in the manifest XML. 它提取了应用文件(只是一个ZIP文件),并在清单XML中修改了多个节点。 For packaging it uses a local copy of 7zip. 对于打包,它使用7zip的本地副本。

function ModifyAppPackage($appPackagePath, $applicationUrl, $clientId){
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem");

$item = get-item $appPackagePath;    
$zipFilePath = Join-Path $item.Directory.FullName $($item.BaseName + ".zip");

Copy-Item $item $zipFilePath;

$unzipDirectory = Join-Path $PSScriptRoot "\Temp";
New-Item -ItemType Directory -Force -Path $unzipDirectory;

if (Test-Path -Path $unzipDirectory\*)
{
    Remove-Item $unzipDirectory\* -Force -Confirm:$false -Recurse:$true;
}

[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFilePath, $unzipDirectory);

$modifiedFile = Join-Path $unzipDirectory "modified.txt"
if (Test-Path -Path $modifiedFile)
{
    $modifiedContent = Get-Content $modifiedFile
    if ($modifiedContent -eq $applicationUrl)
    {
        Remove-Item $unzipDirectory -Confirm:$false -Recurse:$true;
        Remove-Item $zipFilePath;
        return;
    }
    Remove-Item $modifiedFile;
}
$modifiedFileContent = $applicationUrl;
$modifiedFileContent >> $modifiedFile;


$manifestFileName = "AppManifest.xml";
$manifestFilePath = Join-Path $unzipDirectory $manifestFileName;
$manifestXml = [xml](get-content $manifestFilePath);

$nameSpaceManager = New-Object System.Xml.XmlNamespaceManager($manifestXml.NameTable);
$nameSpaceManager.AddNamespace("ns", $manifestXml.DocumentElement.NamespaceURI);

$startPageElement = $manifestXml.SelectSingleNode("/ns:App/ns:Properties/ns:StartPage", $nameSpaceManager);
$StartPage = $applicationUrl + "?{StandardTokens}"
$startPageElement.'#text' = $StartPage


$InstalledEventEndpointElement = $manifestXml.SelectSingleNode("/ns:App/ns:Properties/ns:InstalledEventEndpoint", $nameSpaceManager);
$InstalledEventEndpoint = $applicationUrl + "/Services/AppEventReceiver.svc"
$InstalledEventEndpointElement.'#text' = $InstalledEventEndpoint

$clientIdElement = $manifestXml.SelectSingleNode("/ns:App/ns:AppPrincipal/ns:RemoteWebApplication", $nameSpaceManager);
$clientIdElement.ClientId = $clientId;  

$manifestXml.Save($manifestFilePath);

if (Test-Path -Path $zipFilePath)
{
    Remove-Item $zipFilePath;
}

$pathToZipExe = $("$PSScriptRoot\7za.exe");
[Array]$arguments = "a", "-tzip", "$zipFilePath", "$unzipDirectory\*.*", "-r";
& $pathToZipExe $arguments;

# Cleanup
Remove-Item $unzipDirectory -Confirm:$false -Recurse:$true;
Remove-Item $appPackagePath -Confirm:$false;

# Rename new zip to .app
Rename-Item $zipFilePath $appPackagePath -Force -Confirm:$false;

return $true;

} }

I think it would be possible to store the url in one of custom list in the app. 我认为可以将网址存储在应用程序的自定义列表之一中。 Refer the url from the list. 从列表中引用URL。 Whenever you need to change the url it can be done from the app itself. 每当您需要更改url时,都可以从应用程序本身完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM