9.2
  1. アクセスフィールド値

Word文書のフィールドにアクセスする

日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

Sitecore.Data.Fields.WordDocumentFieldクラスを使ってWordのドキュメントフィールドの値にアクセスできます。Sitecore.Data.Fields.WordDocumentField.Htmlプロパティを使ってフィールド値のHTML表現にアクセスできます。Sitecore.Data.Fields.WordDocumentField.PlainTextプロパティを使ってフィールド値のプレーンテキスト表現にアクセスできます。

Sitecore.Data.Fields.WordDocumentField.Stylesプロパティを使って、そのHTMLに関連付けられたカスケードスタイルシートコードにアクセスできます。例えば、以下の例に基づくWebコントロールを実装し、WordドキュメントフィールドのスタイルとHTMLを出力できます。

namespace Sitecore.Sharedsource.Web.UI.WebControls {

using System; using System.Text.RegularExpressions;

public class RenderWordDocumentFieldRenderer : Sitecore.Web.UI.WebControl {

public string FieldName { get; set; }

protected override void DoRender(System.Web.UI.HtmlTextWriter output) { Sitecore.Data.Items.Item item = this.GetItem();

if (this.FieldName == null || item == null) { return; }

Sitecore.Data.Fields.WordDocumentField wordField = item.Fields"WordField";

if (wordField == null || wordField.BlobId == Sitecore.Data.ID.Null || Regex.IsMatch(wordField.PlainText, "^\\s*$")) { return; }

output.WriteLine(String.Format("<style type=\"text/css\">{0}", wordField.Styles));

output.WriteLine(Sitecore.Web.UI.WebControls.FieldRenderer.Render(item, wordField.InnerField.Name)); } } }

Sitecore.WordOCX.WordOCXUrlManager.GetDownloadLinkメソッドを使って、Wordドキュメントフィールドの値にアクセスするURLを取得することができます。これはWordドキュメント(.docxファイル)です。

例えば、コンテキスト項目内のWordドキュメントフィールドにWordDocument名が付いているWordドキュメントファイルにアクセスするURLを取得する場合:

Sitecore.Data.Items.Item item = Sitecore.Context.Item;

Sitecore.Data.Fields.WordDocumentField wordField = item.Fields"WordDocument";

if (wordField != null && wordField.BlobId != Sitecore.Data.ID.Null && !Regex.IsMatch(wordField.PlainText, "^\\s*$")) { Dictionary<string, string> parameters = new Dictionary<string, string>();

parameters"db" = item.Database.Name;

parameters"blobId" = wordField.BlobId.ToString();

Sitecore.WordOCX.WordOCXUrlManager wordManager =

new Sitecore.WordOCX.WordOCXUrlManager(parameters);

string url = wordManager.GetDownloadLink(); }

この記事を改善するための提案がある場合は、 お知らせください!