CodeGarden 10: The sixth annual Umbraco Developer Conference
June 23-25th 2010 - free ASP.NET MVC pre-conference. Register today!

create document attached file

Go directly to solutionA reply has been marked as a solution
2/8/2010 5:15:05 PMAvatarJesper HaugeLocation: Hillerød, Danmarkposts: 142Karma: 211

I'm doing a custom import of old data from a old umbraco site, and for that reason I need to create some nodes from code.

I've got creation of documents and setting of ordinary properties nailed, but I don't know how to go about population properties of datatype upload. How do you go about this?

Regards
Jesper Hauge

2/8/2010 5:22:12 PMAvatarDirk De GraveLocation: LotenhulleMVP.admin.posts: 2941Karma: 2904
Comment with ID: 25687

Jesper,

I don't know syntax by heart, but would suggest to do following:

create a upload datatype on a test document, upload some file, and have a look at the generated xml in the umbraco.config (when published of course). i'm sure you'll need to first create a media item, and fill upload datatype's value for the document with an xml snippet that represents the media node.

 

Does that make sense?

 

Cheers,

/Dirk

2/8/2010 6:30:15 PMAvatarRichard SoetemanLocation: 2102LB, The NetherlandsVendor.posts: 692Karma: 1412
Comment with ID: 25695

Hi Jesper,

Your import comes a few months too early. This functionality is top prio for UmbImport 1.1. I've build this myself for a client (I don't have the source anymore) and what I did was downloading the Umbraco Source code and reverse engineered the Upload Datatype. It's kinda difficult because its generatiing thumbnails, creating folders etc.

Cheers,

Richard

2/9/2010 11:02:04 AMAvatarJesper HaugeLocation: Hillerød, Danmarkposts: 142Karma: 211
Comment with ID: 25765

Hi Richard

I was afraid that it wasn't easy (since it wasn't already in the umbimport package) - was looking into figuring out how to do it by going through the source code. But it looks like a long haul to get there :(

Thanks for your reply.

Cheers
Jesper

2/9/2010 11:58:57 AMAvatarThomas HöhlerLocation: Bad Homburg, Germanyposts: 1082Karma: 1270
Solution Comment with ID: 25779
0

It depends of how to save the file. Should it be available in the media lib or is it a pure upload field. In the second case you only have to upload the file into the correct folder and populate the filepath to the property value:

var newDoc = Document.MakeNew("MyNewDocument", new DocumentType(1234), new User(0), 5678);
var fileUploadProperty = newDoc.getProperty("MYPROPERTYALIAS");
var mediaId = fileUploadProperty.Id;
var folder = Server.MapPath(string.Format("/media/{0}", mediaId));
if (!Directory.Exists(folder))
Directory.CreateDirectory(folder);
//SAVE THE FILE TO THE FOLDER...
string targetFilename = string.Format("/media/{0}/{1}", mediaId, YOURFILENAME);
string targetFilepath = Server.MapPath(targetFilename);
fileUploadProperty.Value = targetFilepath;
newDoc.Publish(new User(0));
umbraco.library.UpdateDocumentCache(newDoc.Id);

hth, Thomas

2/9/2010 3:40:20 PMAvatarJesper HaugeLocation: Hillerød, Danmarkposts: 142Karma: 211
Comment with ID: 25803

Thanks Thomas - that sounds great I will try it out!

Do you have personal experience doing something like this?

Regards
Jesper Hauge

2/9/2010 4:27:40 PMAvatarThomas HöhlerLocation: Bad Homburg, Germanyposts: 1082Karma: 1270
Comment with ID: 25812

yes, I have implemented such things for our intranet and on some other private projects. In our intranet and extranet I have implemented some windows forms clients which are connecting via webservices to the umbraco installations uploading files like press releases, things that the users have to do once a day and where the users are tired to login into the umbraco backend. Do you need a hand?

Thomas

2/9/2010 8:25:21 PMAvatarJesper HaugeLocation: Hillerød, Danmarkposts: 142Karma: 211
Comment with ID: 25831

Hi again

Thanks a lot. I've done a couple of test runs now, and it looks promising.

The data is there without the thumbnail, which isn't a big problem. Now I just need to put some finishing touches on the code to handle inconsistencies in the source data, before I can get it up and running.

Thanks again.

Cheers
Jesper Hauge

Please login or Sign up To post replies