如何从分层转换访问文档附件

时间:2016-12-17 20:36:54

标签: kentico ascx

我的网站有这样的结构:

Products
    category 1
        item 1
            item 1 attachments
    category 2
        item 2
            item 2 attachments

我已经成功编写了一个分层转换,在顶层显示页面上的数据。我不能为我的生活找出如何访问每个文档的附件。

有人有任何想法吗?

3 个答案:

答案 0 :(得分:1)

如果您正在谈论群组附件(这是您使用附件数据类型在页面中输入字段时),那么为了访问转化中的附件,您需要编写a custom macro(使用文本/ XML转换时)或custom transformation方法。两者都可以很容易地完成。获取附件的代码本身可以是这样的:

public ObjectQuery<AttachmentInfo> GetAttachmentsFromField(string className, int documentID, string attachmentColumnName)
{
    // get class info       
    var classInfo = new FormInfo(DataClassInfoProvider.GetDataClassInfo(className).ClassFormDefinition);
    if (classInfo != null)
    {
        // get attachment field definition            
        var attachmentsField = classInfo.GetFormField(attachmentColumnName);
        if (attachmentsField != null)
        {
            // get attachments strored in the field by GUID
            var attachments = AttachmentInfoProvider.GetAttachments()
                .WhereEquals("3CCC6E6C-56F3-42EB-8385-979973D99C55", attachmentsField.Guid)
                .And()
                .WhereEquals("AttachmentDocumentID", documentID);

            return attachments;
        }
    }
    return null;
}

有了这个,考虑到这个代码引入了几个针对数据库的SQL查询是非常重要的,因此应该通过适当地使用缓存来优化它。

答案 1 :(得分:0)

我认为您的意思是在“属性”中添加未分类的附件 - &gt;附件部分。在这种情况下,yuo可以在转换中注册以下控件:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',  
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-

cli.js',
1 verbose cli   'install',
1 verbose cli   'socket.io' ]
2 info using npm@3.10.9
3 info using node@v6.9.2
4 warn invalid config proxy=""
5 warn invalid config Must be a full url with 'http://'
6 silly loadCurrentTree Starting
7 silly install loadCurrentTree
8 silly install readLocalPackageData
9 silly fetchPackageMetaData socket.io@^1.4.5
10 silly fetchNamedPackageData socket.io
11 silly mapToRegistry name socket.io
12 silly mapToRegistry using default registry
13 silly mapToRegistry registry https://registry.npmjs.org/
14 silly mapToRegistry data Result {
14 silly mapToRegistry   raw: 'socket.io',
14 silly mapToRegistry   scope: null,
14 silly mapToRegistry   escapedName: 'socket.io',
14 silly mapToRegistry   name: 'socket.io',
14 silly mapToRegistry   rawSpec: '',
14 silly mapToRegistry   spec: 'latest',
14 silly mapToRegistry   type: 'tag' }
15 silly mapToRegistry uri https://registry.npmjs.org/socket.io
16 verbose request uri https://registry.npmjs.org/socket.io
17 verbose request no auth needed
18 info attempt registry request try #1 at 3:08:23 PM
19 verbose request id 3d527dc958323a2e
20 verbose etag W/"58524193-241e6"
21 verbose lastModified Thu, 15 Dec 2016 07:09:07 GMT
22 http request GET https://registry.npmjs.org/socket.io
23 http 304 https://registry.npmjs.org/socket.io
24 verbose headers { date: 'Sun, 18 Dec 2016 09:38:24 GMT',
24 verbose headers   via: '1.1 varnish',
24 verbose headers   'cache-control': 'max-age=300',
24 verbose headers   etag: 'W/"58524193-241e6"',
24 verbose headers   age: '172',
24 verbose headers   connection: 'keep-alive',
24 verbose headers   'x-served-by': 'cache-sin6924-SIN',
24 verbose headers   'x-cache': 'HIT',
24 verbose headers   'x-cache-hits': '1',
24 verbose headers   'x-timer': 'S1482053904.936429,VS0,VE0',
24 verbose headers   vary: 'Accept-Encoding' }
25 silly get cb [ 304,
25 silly get   { date: 'Sun, 18 Dec 2016 09:38:24 GMT',
25 silly get     via: '1.1 varnish',
25 silly get     'cache-control': 'max-age=300',
25 silly get     etag: 'W/"58524193-241e6"',
25 silly get     age: '172',
25 silly get     connection: 'keep-alive',
25 silly get     'x-served-by': 'cache-sin6924-SIN',
25 silly get     'x-cache': 'HIT',
25 silly get     'x-cache-hits': '1',
25 silly get     'x-timer': 'S1482053904.936429,VS0,VE0',
25 silly get     vary: 'Accept-Encoding' } ]
26 verbose etag https://registry.npmjs.org/socket.io from cache
27 verbose get saving socket.io to C:\Users\HP\AppData\Roaming\npm-cache\registry.npmjs.org\socket.io\.cache.json
28 verbose correctMkdir C:\Users\HP\AppData\Roaming\npm-cache correctMkdir not in flight; initializing
29 silly install normalizeTree
30 silly loadCurrentTree Finishing
31 silly loadIdealTree Starting
32 silly install loadIdealTree
33 silly cloneCurrentTree Starting
34 silly install cloneCurrentTreeToIdealTree
35 silly cloneCurrentTree Finishing
36 silly loadShrinkwrap Starting
37 silly install loadShrinkwrap
38 silly loadShrinkwrap Finishing
39 silly loadAllDepsIntoIdealTree Starting
40 silly install loadAllDepsIntoIdealTree
41 silly resolveWithNewModule socket.io@1.7.2 checking installable status
42 silly cache add args [ 'socket.io@^1.4.5', null ]
43 verbose cache add spec socket.io@^1.4.5
44 silly cache add parsed spec Result {
44 silly cache add   raw: 'socket.io@^1.4.5',
44 silly cache add   scope: null,
44 silly cache add   escapedName: 'socket.io',
44 silly cache add   name: 'socket.io',
44 silly cache add   rawSpec: '^1.4.5',
44 silly cache add   spec: '>=1.4.5 <2.0.0',
44 silly cache add   type: 'range' }
45 silly addNamed socket.io@>=1.4.5 <2.0.0
46 verbose addNamed ">=1.4.5 <2.0.0" is a valid semver range for socket.io
47 silly addNameRange { name: 'socket.io', range: '>=1.4.5 <2.0.0', hasData: false }
48 silly mapToRegistry name socket.io
49 silly mapToRegistry using default registry
50 silly mapToRegistry registry https://registry.npmjs.org/
51 silly mapToRegistry data Result {
51 silly mapToRegistry   raw: 'socket.io',
51 silly mapToRegistry   scope: null,
51 silly mapToRegistry   escapedName: 'socket.io',
51 silly mapToRegistry   name: 'socket.io',
51 silly mapToRegistry   rawSpec: '',
51 silly mapToRegistry   spec: 'latest',
51 silly mapToRegistry   type: 'tag' }
52 silly mapToRegistry uri https://registry.npmjs.org/socket.io
53 verbose addNameRange registry:https://registry.npmjs.org/socket.io not in flight; fetching
54 verbose get https://registry.npmjs.org/socket.io not expired, no request
55 silly addNameRange number 2 { name: 'socket.io', range: '>=1.4.5 <2.0.0', hasData: true }
56 silly addNameRange versions [ 'socket.io',
56 silly addNameRange   [ '0.3.8',
56 silly addNameRange     '0.4.0',
56 silly addNameRange     '0.4.1',
56 silly addNameRange     '0.5.1',
56 silly addNameRange     '0.5.3',
56 silly addNameRange     '0.6.0',
56 silly addNameRange     '0.6.1',
56 silly addNameRange     '0.6.3',
56 silly addNameRange     '0.6.4',
56 silly addNameRange     '0.6.5',
56 silly addNameRange     '0.6.6',
56 silly addNameRange     '0.6.7',
56 silly addNameRange     '0.6.8',
56 silly addNameRange     '0.6.9',
56 silly addNameRange     '0.6.10',
56 silly addNameRange     '0.6.11',
56 silly addNameRange     '0.6.12',
56 silly addNameRange     '0.6.14',
56 silly addNameRange     '0.6.15',
56 silly addNameRange     '0.6.16',
56 silly addNameRange     '0.6.17',
56 silly addNameRange     '0.6.18',
56 silly addNameRange     '0.7.0',
56 silly addNameRange     '0.7.1',
56 silly addNameRange     '0.7.2',
56 silly addNameRange     '0.7.3',
56 silly addNameRange     '0.7.4',
56 silly addNameRange     '0.7.5',
56 silly addNameRange     '0.7.6',
56 silly addNameRange     '0.7.7',
56 silly addNameRange     '0.7.8',
56 silly addNameRange     '0.7.9',
56 silly addNameRange     '0.7.10',
56 silly addNameRange     '0.7.11',
56 silly addNameRange     '0.8.0',
56 silly addNameRange     '0.8.1',
56 silly addNameRange     '0.8.2',
56 silly addNameRange     '0.8.3',
56 silly addNameRange     '0.8.4',
56 silly addNameRange     '0.8.5',
56 silly addNameRange     '0.8.6',
56 silly addNameRange     '0.8.7',
56 silly addNameRange     '0.9.0',
56 silly addNameRange     '0.9.1',
56 silly addNameRange     '0.9.1-1',
56 silly addNameRange     '0.9.2',
56 silly addNameRange     '0.9.3',
56 silly addNameRange     '0.9.4',
56 silly addNameRange     '0.9.5',
56 silly addNameRange     '0.9.6',
56 silly addNameRange     '0.9.7',
56 silly addNameRange     '0.9.8',
56 silly addNameRange     '0.9.9',
56 silly addNameRange     '0.9.10',
56 silly addNameRange     '0.9.11',
56 silly addNameRange     '0.9.12',
56 silly addNameRange     '0.9.13',
56 silly addNameRange     '0.9.14',
56 silly addNameRange     '0.9.15',
56 silly addNameRange     '0.9.16',
56 silly addNameRange     '1.0.0-pre',
56 silly addNameRange     '1.0.0-pre2',
56 silly addNameRange     '1.0.0-pre3',
56 silly addNameRange     '1.0.0-pre4',
56 silly addNameRange     '1.0.0-pre5',
56 silly addNameRange     '0.9.17',
56 silly addNameRange     '1.0.0',
56 silly addNameRange     '1.0.1',
56 silly addNameRange     '1.0.2',
56 silly addNameRange     '1.0.3',
56 silly addNameRange     '1.0.4',
56 silly addNameRange     '1.0.5',
56 silly addNameRange     '1.0.6',
56 silly addNameRange     '1.1.0',
56 silly addNameRange     '1.2.0',
56 silly addNameRange     '1.2.1',
56 silly addNameRange     '1.3.0',
56 silly addNameRange     '1.3.1',
56 silly addNameRange     '1.3.2',
56 silly addNameRange     '1.3.3',
56 silly addNameRange     '1.3.4',
56 silly addNameRange     '1.3.5',
56 silly addNameRange     '1.3.6',
56 silly addNameRange     '1.3.7',
56 silly addNameRange     '1.4.0',
56 silly addNameRange     '1.4.1',
56 silly addNameRange     '1.4.2',
56 silly addNameRange     '1.4.3',
56 silly addNameRange     '1.4.4',
56 silly addNameRange     '1.4.5',
56 silly addNameRange     '1.4.6',
56 silly addNameRange     '1.4.7',
56 silly addNameRange     '1.4.8',
56 silly addNameRange     '1.5.0',
56 silly addNameRange     '1.5.1',
56 silly addNameRange     '1.6.0',
56 silly addNameRange     '1.7.0',
56 silly addNameRange     '1.7.1',
56 silly addNameRange     '1.7.2' ] ]
57 silly addNamed socket.io@1.7.2
58 verbose addNamed "1.7.2" is a plain semver version for socket.io
59 silly mapToRegistry name socket.io
60 silly mapToRegistry using default registry
61 silly mapToRegistry registry https://registry.npmjs.org/
62 silly mapToRegistry data Result {
62 silly mapToRegistry   raw: 'socket.io',
62 silly mapToRegistry   scope: null,
62 silly mapToRegistry   escapedName: 'socket.io',
62 silly mapToRegistry   name: 'socket.io',
62 silly mapToRegistry   rawSpec: '',
62 silly mapToRegistry   spec: 'latest',
62 silly mapToRegistry   type: 'tag' }
63 silly mapToRegistry uri https://registry.npmjs.org/socket.io
64 verbose addRemoteTarball https://registry.npmjs.org/socket.io/-/socket.io-1.7.2.tgz not in flight; adding
65 verbose addRemoteTarball [ 'https://registry.npmjs.org/socket.io/-/socket.io-1.7.2.tgz',
65 verbose addRemoteTarball   '83bbbdf2e79263b378900da403e7843e05dc3b71' ]
66 verbose stack Error: kill ENOSYS
66 verbose stack     at exports._errnoException (util.js:1022:11)
66 verbose stack     at process.kill (internal/process.js:172:13)
66 verbose stack     at process.listener (C:\Program Files\nodejs\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:86:15)
66 verbose stack     at emitNone (events.js:91:20)
66 verbose stack     at process.emit (events.js:185:7)
66 verbose stack     at processEmit (C:\Program Files\nodejs\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32)
66 verbose stack     at processEmit (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32)
66 verbose stack     at Signal.wrap.onsignal (internal/process.js:199:44)
67 verbose cwd C:\xampp\htdocs\major\wb\ss\demo
68 error Windows_NT 10.0.14393
69 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "socket.io"
70 error node v6.9.2
71 error npm  v3.10.9
72 error code ENOSYS
73 error errno ENOSYS
74 error syscall kill
75 error kill ENOSYS
76 error If you need help, you may report this error at:
76 error     <https://github.com/npm/npm/issues>
77 verbose exit [ 1, true ]

并像这样使用它:

<%@ Register Src="~/CMSInlineControls/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %>

答案 2 :(得分:0)

我前一段时间写了pretty detailed blog post。它描述了与Enn答案非常相似的属性,但提供了有关您为何做特定事情的详细信息。