Įvykiai
Power BI DataViz Pasaulio čempionatas
02-14 16 - 03-31 16
Su 4 galimybes įvesti, galite laimėti konferencijos paketą ir padaryti jį LIVE Grand Finale Las Vegase
Sužinokite daugiauŠi naršyklė nebepalaikoma.
Atnaujinkite į „Microsoft Edge“, kad pasinaudotumėte naujausiomis funkcijomis, saugos naujinimais ir techniniu palaikymu.
When you develop a large number of files to use as Web resources, you can save yourself the work of manually adding them through the application. Many Web resources can be developed and tested outside of Model-driven apps and then imported.
This sample provides a simplified example of this process.
Download the sample: Import files as web resources.
Internet connection is required to download the sample project and to restore the NuGet packages used in the sample project.
The sample code included in the SDK download package includes the following files required by this sample:
ImportJob.xml
This file provides data about the Web Resource records that will be created. For each file, it contains the following data:
path: The path to each file from the FilesToImport folder.
displayName: The display name for the Web resource.
description: A description of what each file does.
name: The name that will be used for the Web Resource.
Pastaba
type: Specifies the type of Web Resource to create using the integer values found in Web Resource Types.
FilesToImport/ShowData.htm
This HTML Web resource requires each of the other files to display the following table.
First Name | Last Name |
---|---|
Apurva | Dalia |
Ofer | Daliot |
Jim | Daly |
Ryan | Danner |
Mike | Danseglio |
Alex | Darrow |
FilesToImport/CSS/Styles.css
This file provides the CSS Styles used in ShowData.htm.
FilesToImport/Data/Data.xml
This file contains the list of names that is displayed in the table.
FilesToImport/Script/Script.js
This file contains a JScript library that contains information about the relative location of the Data.xml file and the Transform.xslt file. It also contains the showData
function that transforms the data and adds it to the ShowData.htm page.
FilesToImport/XSL/Transform.xslt
This file contains the XSL definition of how to transform the data into an HTML table.
Web Resources are organization-owned records so they can be created using either theIOrganizationService.Create method or by using the CreateRequest message and the IOrganizationService.Execute method. This sample shows how to use the SolutionUniqueName
optional parameter to associate a Web resource with a specific solution when it's created. Using an optional parameter requires using the CreateRequest message.
The WebResource.Content property requires a Base 64 string representing the binary contents of the file. The following sample is the method used to convert the file into the required type.
//Encodes the Web Resource File
static public string getEncodedFileContents(String pathToFile)
{
FileStream fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read);
byte[] binaryData = new byte[fs.Length];
long bytesRead = fs.Read(binaryData, 0, (int)fs.Length);
fs.Close();
return System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
}
The ImportJob.xml file demonstrates how the data about the files being imported and the data about the Web Resource to create are combined. In particular, in order for relative links between related files to continue to function, the name of the Web resources you create must preserve information about the relative position of the files on disk using simulated directories in the file name. Because of the data in the ImportJob.xml file all these related Web resource files will be created under a common virtual folder.
Pastaba
It is not necessary to publish Web resources when they are created. It is necessary to publish them when they are updated.
The following portion of the ImportWebResources.cs file expects the following variables:
_customizationPrefix
: The customization prefix of the SDK Samples publisher. If this publisher does not exist it will be created with the customization prefix of "sample"._ImportWebResourcesSolutionUniqueName
: The unique name of the Import Web Resources Sample Solution created in this sample. The value is ImportWebResourcesSample
.//Read the descriptive data from the XML file
XDocument xmlDoc = XDocument.Load("../../ImportJob.xml");
//Create a collection of anonymous type references to each of the Web Resources
var webResources = from webResource in xmlDoc.Descendants("webResource")
select new
{
path = webResource.Element("path").Value,
displayName = webResource.Element("displayName").Value,
description = webResource.Element("description").Value,
name = webResource.Element("name").Value,
type = webResource.Element("type").Value
};
// Loop through the collection creating Web Resources
int counter = 0;
foreach (var webResource in webResources)
{
//Set the Web Resource properties
WebResource wr = new WebResource
{
Content = getEncodedFileContents(@"../../" + webResource.path),
DisplayName = webResource.displayName,
Description = webResource.description,
Name = _customizationPrefix + webResource.name,
LogicalName = WebResource.EntityLogicalName,
WebResourceType = new OptionSetValue(Int32.Parse(webResource.type))
};
// Using CreateRequest because we want to add an optional parameter
CreateRequest cr = new CreateRequest
{
Target = wr
};
//Set the SolutionUniqueName optional parameter so the Web Resources will be
// created in the context of a specific solution.
cr.Parameters.Add("SolutionUniqueName", _ImportWebResourcesSolutionUniqueName);
CreateResponse cresp = (CreateResponse)_serviceProxy.Execute(cr);
// Capture the id values for the Web Resources so the sample can delete them.
_webResourceIds[counter] = cresp.id;
counter++;
Console.WriteLine("Created Web Resource: {0}", webResource.displayName);
}
It is not necessary to publish Web resources when they are created. It is necessary to publish them when they are updated.
Įvykiai
Power BI DataViz Pasaulio čempionatas
02-14 16 - 03-31 16
Su 4 galimybes įvesti, galite laimėti konferencijos paketą ir padaryti jį LIVE Grand Finale Las Vegase
Sužinokite daugiauMokymas
Mokymosi kelias
Use advance techniques in canvas apps to perform custom updates and optimization - Training
Use advance techniques in canvas apps to perform custom updates and optimization
Sertifikatas
Microsoft Certified: Power Platform Developer Associate - Certifications
Demonstrate how to simplify, automate, and transform business tasks and processes using Microsoft Power Platform Developer.
Dokumentacija
Create, manage, and publish model-driven apps using code - Power Apps
Learn about how to create, manage, and publish model-driven apps using code in Power Apps.
Webpage (HTML) Web Resources (model-driven apps) - Power Apps
This article covers how to implement HTML web resources and its capabilities and limitations
Web Resources (model-driven apps) - Power Apps
Web resources are virtual files that are stored in the Microsoft Dataverse database and that you can retrieve by using a unique URL address.