I have to get some image data from SharePoint library in my server side console app.
However, i only find the some download to PC solution in internet, so how get the image directly.
my code
foreach(SPListItem item in docLib.Items)
{
// Access the file
SPFile file = item.File;
if(file != null)
{
// retrieve the file as a byte array
byte[] bArray = file.OpenBinary();
string filePath = Path.Combine("c:\\temp", file.Name);
//open the file stream and write the file
using(FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
{
fs.Write(bArray, 0, bArray.Length);
MemoryStream ms = new MemoryStream(bArray)
Image myImage = Image.FromStream(ms); // i get my image now, but i have to download it to PC first.
}
}
}
myImage.Save(@"C:\Users\HIHI\Downloads\asd.TIFF", System.Drawing.Imaging.ImageFormat.Png);