如何在列表的共享点附件中上传图像 [英] How to upload image in sharepoint attachment of list
问题描述
我想在本地PC的共享点列表的附件列中上传或添加图像. (sharepoint 2013),其工作正常,但在其他服务器计算机(UAT服务器)上,相同的代码未上载图像.它给出了错误
i want to upload or add image in attachment column of sharepoint list.on my local pc (sharepoint 2013 ) its working fine but on other server machine ( UAT server ) same code is not uploading image .its giving error
"找不到文件'找不到文件'c:\ windows \ system32 \ inetsrv \ Mehran2.jpg'."
"Could not find file 'Could not find file 'c:\windows\system32\inetsrv\Mehran2.jpg'.."
尽管我正在从 "加载图像d:\ working \ Mehran2.jpg.图像可用,并且正如我在本地计算机上告诉您的那样,该图像可以工作,但是来自UAT服务器,或者相同的东西无法正常工作.
although i am loading image from " d:\working\Mehran2.jpg ".Image is available and as i told you on my local machine its working but from UAT server or same things is not working .
我的代码是:
私人布尔AddAttachments2(SPListItem NewItem)
{
bool标志= true;
FileInfo附件=新的FileInfo(fuImages.PostedFile.FileName);
//{
FileStream fs =新的FileStream(attachment.FullName,FileMode.Open,FileAccess.Read);
试试
{
//创建文件流长度的字节数组
byte [] ImageData =新的byte [fs.Length];
//将字节块从流读取到字节数组中
fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));
字符串strpath = System.IO.Path.GetExtension(attachment.Name);
if(strpath!=".jpg"&& strpath!=".jpeg"&& strpath!=".gif"&& strpath!=".png"))
{
ltrAlert.Text =仅允许使用无效的文件格式(JPG,Gif和Png).记录未保存.";
div_message.Style.Add("color",#FF0000");
标志=假;
}
long lngfilesize = fs.Length/1024;
如果(lngfilesize> 2048)
{
ltrAlert.Text =文件大小必须小于2MB.未保存记录.";
div_message.Style.Add("color",#FF0000");
标志=假;
}
fs.Close();
NewItem.Attachments.Add(attachment.Name,ImageData);
}
catch(异常例外)
{
Helper.LogException("postAdForm-> AddAttachments2",例如);
}
返回标志;
}
private bool AddAttachments2(SPListItem NewItem)
{
bool flag = true;
FileInfo attachment= new FileInfo(fuImages.PostedFile.FileName);
// {
FileStream fs = new FileStream(attachment.FullName, FileMode.Open, FileAccess.Read);
try
{
// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
string strpath = System.IO.Path.GetExtension(attachment.Name);
if (strpath != ".jpg" && strpath != ".jpeg" && strpath != ".gif" && strpath != ".png")
{
ltrAlert.Text = "Invalid file format only (JPG,Gif and Png) allowed. Record not Saved.";
div_message.Style.Add("color", "#FF0000");
flag = false;
}
long lngfilesize = fs.Length / 1024;
if (lngfilesize > 2048)
{
ltrAlert.Text = "File size must be under 2MB.Record not Saved.";
div_message.Style.Add("color", "#FF0000");
flag = false;
}
fs.Close();
NewItem.Attachments.Add(attachment.Name, ImageData);
}
catch (Exception ex)
{
Helper.LogException("PostAdForm -> AddAttachments2", ex);
}
return flag;
}
谢谢
推荐答案
您上传时无法按客户端路径访问文件.
https://sharepoint.stackexchange.com/questions/42980/issue-with-saving-image-file-onto-server-from-client-machine
尝试如果您不想将文件保存到服务器,则使用PostFile.PostedFile.InputStream .
https://social.msdn.microsoft.com/Forums/azure/en-US/1d559668-4025-45cb-ad53-caf665f86920/store-imagesfiles-into-blob-storage?forum=windowsazuredata
  ;
最佳问候
Lee
这篇关于如何在列表的共享点附件中上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!