create new document and attachment by ADO.Net

hadi tag asked on June 1, 2015 07:51

Hi,

Which table should be filled out to create a new document with ado.net (in sql server script)?

i fill [dbo].[CMS_Tree] and [dbo].[CMS_Document] and [dbo].[CMS_Attachment]

but when press edit button for added document, current page redirected to my parent page

Recent Answers


Brenden Kehren answered on June 1, 2015 13:35

Directly trying to fill all the necessary tables and fields directly/manually is frowned upon. You'll end up fragmenting and/or corrupting your data, essentially causing your site to be useless.

Is there a reason you're choosing to not use the API?

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 1, 2015 18:18

Look at the API examples in your Kentico Installation. Search "API Examples". It will give you the API Calls and it makes it easy. Create Document, Add Attachment, etc.

0 votesVote for this answer Mark as a Correct answer

hadi tag answered on June 1, 2015 18:52

hi Brenden ,

I thank you for answer.

I choose sql server script because i want get some document and attachment from DB1 and insert to DB2 with a attachment file sharing for 2 databases. but when i use from API, i can not handle this issue

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 1, 2015 20:54

Not sure why you are doing that, but you can use the API and Rest Services API and accomplish the same thing.

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 2, 2015 02:11

To add to what Charles pointed out, if you use a USING statement you can specify the connection string to use for that block of code and then perform your insert using the same dataset or object. Doesn't make any sense at all to risk your data integrity at all to do manual sql CRUD statements when an API is present.

0 votesVote for this answer Mark as a Correct answer

hadi tag answered on June 2, 2015 06:52 (last edited on June 2, 2015 06:58)

when i use API and this code:

var newAttachment = new AttachmentInfo
                {
                    AttachmentDocumentID = node.DocumentID,
                    AttachmentExtension = item.FileType,
                    AttachmentSize = (int)item.FileSize,
                    AttachmentName = item.FileName,
                    AttachmentMimeType = MimeTypeHelper.GetMimetype(item.FileType),
                    AttachmentTitle = item.FileName,
                    AttachmentDescription = "",
                    AttachmentSiteID = CMS.SiteProvider.SiteContext.CurrentSiteID,
                    AttachmentGUID = guid
                };
                DocumentHelper.AddAttachment(node, "DocFile", guid, groupGuid, newAttachment, provider);
                node.Update();

For each record in the CMS_Attachment table inserted, two different AttachmentGuid inserted. While I have used a single guid for both attachments.

This makes it, both attachments can't take a physical file, because file system use from attachment guid for attachment file name.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.