Changing file upload

Topics: ASP.NET 2.0, Business Logic Layer
May 10, 2008 at 6:32 AM
Hi, I am fairly new to BlogEngine.NET, but I am trying to migrate my old WordPress blog to BlogEngine.NET. There are a couple of things I need to look at, before being able to succesfully migrate.

At this moment, when you upload a file with a post the file is uploaded and just a piece of text is pasted in the editor. When the post is saved (and I am still using the XML data provider) it saves no extra data whatsoever about this file. It's just a link in the post.

What I wanted to accomplish is this:
When I upload a file to a post, I would like it to be stored as an extra element in the XML file. I would also like to add a couple child-elements, with for example a description, file size, etc. This way it probably would be easier for themes to show a small file list below the post just made, containing the files uploaded with a post.

Check the following url for an example on my old blog.
http://www.depl0y.com/personal/xmldocument-fluent-interface

Now I am pretty new to making BlogEngine.NET extensions, but if someone could give me a couple of hints about what I am trying to accomplish, that would be great.
May 10, 2008 at 7:37 AM
Ok, I started looking around in the source code a bit, and I found one way to maybe complete this. I could change the Add_Entry page and make it store the file info somewhere else... somehow.

But I wonder if this can be done by extension instead of changing the application code itself.
May 10, 2008 at 9:44 AM
Sorry about this, but I got my little project almost working. Above the file upload control it now shows a table, which shows which files are attached to a post. I changed the default behaviour for the upload control to not insert a link to the file immediately when a file is uploaded. The attached files are also saved to the post XML files and reloaded when needed again.

When you click on a filename in the "Attached files" table, I want it to insert a link to the file in the text and I think I found the code to insert a text in the tinyMCE editor.

Except... when I trigger my javascript from my files table, it does not insert the links in the editor, but on the top of the page. If I put that exact javascript somewhere in the page, it DOES insert the text in the tinyMCE editor.

This is the JS I got:

function InsertFileLink(virtualPath, filename)
{
    tinyMCE.execCommand('mceInsertContent', false, '<a href="' + virtualPath + '" rel="enclosure">' + filename + '</a>');
}

<span onclick="InsertFileLink('/BlogEngine.Web/file.axd?file=KeyMagic.inf', 'KeyMagic.inf (5.81 kb)');">KeyMagic.inf (5.81 kb)</span>

Does someone know why it does not insert my text in the editor, but on the top of the page?
May 10, 2008 at 9:57 AM
Edited May 10, 2008 at 3:36 PM
Ok, I'm on fire! :P.

It all seems to work, except sometimes it somehow trashes my AttachedFiles list and then it is removed from the post? It seems like there is some other save/load code that I haven't changed yet...

Getting there..

Update:
It all seems to work, now over to getting the files to show in my current skin...
May 10, 2008 at 9:01 PM
Edited May 10, 2008 at 9:02 PM
Ok, I think I got it to work and it was easier than I tought.

I posted a screenie of my admin panel 'Add Entry' page and one screenshot of my post.

Add Entry screen
Post

I would love to see this functionality included in a next release.
Aug 27, 2008 at 10:35 AM
Hi
 I'm very interested in this, but where can I find the solution?
I don't want to create this from the beginning if it is solved.

thanks