How to insert a Figure type document using Kentico API?

Binod Paikaray asked on March 8, 2017 14:56

Hello,

I've two environments of my Kentico CMS site and I need to get a node along with it's children nodes from say production site and insert that full node along with the children nodes (which contain Figure nodes and other attachment nodes as well) in the QA site. After lot of struggle, I'm able to insert nodes and it's hierarchy but attachments are not able to be added. When I try using "DocumentHelper.AddAttachment" method, it requires a file path which I don't have because I need that file from the other environment only on the fly. I tried lot of things but no success yet so finally came here to get some help from the experts. Please let me know a solution for this.

Thanks

Binod Paikaray

Recent Answers


Trevor Fayas answered on March 8, 2017 15:19

My recommendation is to first download the file to a temporary spot on the live site, then you'll have the file path that you can then create the attachment with! Only way i see, since the other two methods fot he AddAttachment are for a HttpPostedFile (which requires a post to the code), or a GUID of the file attachment GUID (which also requires either a file name, or a httppostedfile to create)

string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;

// Create a new WebClient instance.
using (WebClient myWebClient = new WebClient())
{
    myStringWebResource = remoteUri + fileName;
    // Download the Web resource and save it into the current filesystem folder.
    myWebClient.DownloadFile(myStringWebResource, fileName);        
}
0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 8, 2017 15:43 (last edited on March 8, 2017 15:46)

I would try to publish back to the staging server (QA Environment). Check out content staging and Synchronization. We have our environments set up both ways i.e. Bi-directional content staging. Normally you publish from staging(QA) to production, but you can do it vice versa. You should be able move the part of the tree with attachments.

3 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on March 11, 2017 19:48 (last edited on March 12, 2017 15:47)

Thanks everyone for your help!

Peter M, I tried to configure these Content Staging and Synchronization but when at the source site I enter my target site's server name in "Server service URL" textbox and check for the availability of server, it always gives me error. Then I tried to hit the whole URL (http://mysite.com//CMSPages/Staging/SyncServer.asmx), it's giving me HTTP 404 error (The resource cannot be found.). As per a reply on some other post I added the extension .asmx in the allowed extensions in the requestfiltering section as well but no success. Then I checked my site's physical path and found that this syncserver.asmx file is physically present there. I'm bit confused that whether this file should be physically present there or not because I didn't find it at either of three environments of my site. Please let me know if I'm doing something wrong.

Thanks

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on March 14, 2017 13:48

Can I please get some suggestion or help regarding the above issue? I've already tried lot of things from my end. Please give me some solution for this.

Thanks

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 14, 2017 14:06

If you are doing staging and one site cannot see the other, make sure you have a host file that points the domain to the right ip address (in this case "my site.com"). The staging server must be able to bring up the site it is pushing to in order to push it's data. If the two sites are on the same computer/server, then set it to 127.0.0.1 (home)

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on March 14, 2017 16:20 (last edited on March 14, 2017 16:20)

My sites are able to connect each other but before that even after enabling the Staging Service at the my DEV site, the service is not running and the URL http://mysite.com/CMSPages/staging/syncserver.asmx (dummy domain name here) is always giving me HTTP 404 (The resource cannot be found) error.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 14, 2017 16:30

Can you take a screen shot of your Staging-> Servers -> [the server] setup?

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on March 14, 2017 17:37 (last edited on March 14, 2017 17:43)

Staging Server

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 14, 2017 17:39

You'll need to use a file share or place it somewhere publically so we can see it, at minimum email it to me at tfayas@hbs.net

Your image won't show because it's pointing to your local drive.

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on March 14, 2017 18:26 (last edited on March 14, 2017 19:45)

I'm sorry for uploading wrong path. I had realised that it will not be visible but couldn't get option to delete that reply after being posted so thought to upload again and here it is. Please let me know if you can see the below images now.

Staging

Target

Thanks

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 14, 2017 19:11

Those must be private, also can't see :(

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on March 15, 2017 12:42 (last edited on March 15, 2017 12:42)

Thanks very-very much Trevor for the solution!!! It really helped me a lot and worked!

I added the SyncServer.asmx file in my target server site and then everything worked.

But only one problem is that the synchronization is not maintaining the order of the nodes (or child nodes). Is there any specific configuration need to be done for that?

Thanks very much again !!!

0 votesVote for this answer Mark as a Correct answer

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