[英]system.drawing.image to spfile
我有一個圖像需要保存在共享文檔下的Sharepoint站點中
由於各種原因,圖像必須位於system.drawing.image中,並保存在sharepoint站點內的共享文檔中。 它不必保存在本地硬盤中。
你有任何解決方案嗎?
到目前為止,我正在試着
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
byte[] imagebyte = ms.ToArray();
然后Savebinary函數的streamreader但沒有喜悅
過了一會兒,我設法找到一個避免圖片庫的解決方案
void imageSave(System.Drawing.Image imageTobeSaved)
{
using (SPSite site = new SPSite("http://sptestsite/"))
{
using (SPWeb web = site.RootWeb)
{
SPFolder myLibrary = web.Folders["Shared%20Documents"];
var stream = new System.IO.MemoryStream();
string filename = "picture.jpg";
MemoryStream ms = new MemoryStream();
imageTobeSaved.Save(ms, System.Drawing.Imaging.ImageFormat.jpg);
byte[] ImageByte = ms.ToArray();
SPFile spfile = myLibrary.Files.Add(filename, ImageByte);
myLibrary.Update();
}
}
}
初學者十,你需要在這里更改一些硬編碼設置
public void addToSharepointImageList(string folderName, string fileName, byte[] content)
{
string path = @"\\yoursite\yourlistname\";
string baseSharePointPath = "http://yoursite/";
string listName = "yourlistname";
SharePointImagingService.Imaging svc = null;
try
{
path += folderName;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
#region create sharepoint service
svc = new SharePointImagingService.Imaging();
NetworkCredential nc = new NetworkCredential("username", "password", "domain");
svc.Credentials = nc;
//svc.Credentials = System.Net.CredentialCache.DefaultCredentials;
svc.Url = baseSharePointPath + listName+ "/_vti_bin/imaging.asmx";
svc.Discover();
#endregion
svc.Upload(baseSharePointPath + listName, folderName, content, fileName, true);
}
catch (Exception e)
{
//deal with error
}
finally
{
svc.Dispose();
}
}
或者,如果您嘗試將文件直接保存到非圖像列表,則可以將sharepoint視為巨大的文件共享,只需打開文件流並在其中寫入字節數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.