Library Extraction Code Updated
An updated version of the blog post Save Images from the Images and Documents module back to the file system post which allows for all libraries and all files to be processed, thought it may be useful for people if they are doing the same migration work we are.
Rob
protected void cmdExtract_Click(object sender, EventArgs e)
string storage = "C:\\Source\\Pan\\Library\\";
var man = new LibraryManager();
IList libraries = man.GetAllLibraries();
foreach (ILibrary l in libraries)
ILibrary lib = l;
IList allImages = lib.GetItems();
int i = 0;
foreach (IContent contentItem in allImages)
IContent cnt = man.GetContent(contentItem.ID);
string name = (string)cnt.GetMetaData("Name");
string ext = (string)cnt.GetMetaData("Extension");
byte[] buffer1 = (byte[])cnt.Content;
writeByteArrayToFile(buffer1, storage + name + ext);
i++;
Response.Write(i.ToString() + "-" + "items have been uploaded to:" + storage + "<
br
/>");
public bool writeByteArrayToFile(byte[] buff, string fileName)
bool response = false;
try
FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(buff);
bw.Close(); //Thanks Karlo for pointing out!
response = true;
catch (Exception ex)
Console.WriteLine(ex.Message);
return response;
Sorry moderatos, this should have gone in the 3.X forum section, not in 4.X, i will pay more attention next time :)