Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Rename media files programatically
raihaniqbal
#1 Posted : Saturday, 24 September 2011 2:48:16 AM(UTC)
Rank: Newbie

Joined: 24/09/2011(UTC)
Posts: 2
Location: Dhaka, Bangladesh

Hi,

I need to write some maintenance code that will rename files in a specific folder.

Code:

foreach (IGalleryObject audioFile in audioAlbum.GetChildGalleryObjects())
{
  audioFile.Title = String.Format("audio_30_1_{0}", counter++);
  GalleryObjectController.SaveGalleryObject(audioFile);
}


This code throws an exception
Quote:
This gallery object (ID 36, GalleryServerPro.Business.Audio) is not updateable.


How can resolve this?

Thanks
raihaniqbal
#2 Posted : Saturday, 24 September 2011 3:01:34 AM(UTC)
Rank: Newbie

Joined: 24/09/2011(UTC)
Posts: 2
Location: Dhaka, Bangladesh

OK. I've managed to resolve the error by adding audioFile.IsWriteable = true but it didnt serve my purpose. My code just renames the Title but it doesnt rename the physical file on disk.

Code:
foreach (IGalleryObject audioFile in audioAlbum.GetChildGalleryObjects())
{
  audioFile.Title = String.Format("audio_30_1_{0}", counter++);
  audioFile.IsWriteable = true; // UPDATE
  GalleryObjectController.SaveGalleryObject(audioFile);
}


Thanks
Roger Martin
#3 Posted : Saturday, 24 September 2011 10:06:56 AM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,300
Location: Fort Atkinson, WI

GSP does not support renaming the files. The closest you can get is to rename the files using the .NET File API and then re-sync the containing album. But this results in the deletion and inserting of a new media object, meaning you will lose info like the caption and ordering. Maybe that is acceptable...
Roger Martin
Creator and Lead Developer of Gallery Server Pro
Rss Feed  Atom Feed
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.