自动上传编辑器中的远程图片与自动替换alt标签
2011-12-13 11:13
453 查看
#region 增加一条数据
/// <summary>
/// 增加一条数据
/// </summary>
public int Add( NewsEntity model )
{
//未添加图片说明的添加说明
MatchCollection matchs = Regex.Matches(model.Content, "<img.*/?>(<img/>)?", RegexOptions.IgnoreCase);
Match filePath;
foreach (Match match in matchs)
{
model.Content = model.Content.Replace(match.Value, match.Value.Replace("alt=\"\"", "alt=\"" + model.Title + "\""));
//将远程包含http和不是chinayq.com服务器中的图片上传
filePath = Regex.Match(match.Value, @"(http)+.*(jpg|png|gif|jpeg)", RegexOptions.IgnoreCase);
if (filePath.Success && filePath.Value.IndexOf("chinayq.com") < 0)
{
model.Content = model.Content.Replace(filePath.Value, WebUtility.PicOperate.UploadHttpFile(filePath.Value.Replace("\"", "")));
}
}
return dal.Add(model);
}
#endregion
/// <summary>
/// 上传远程文件到本地服务器
/// </summary>
/// <param name="filePath">远程文件</param>
/// <returns></returns>
public static string UploadHttpFile(string urlPath)
{
string filePath =string.Format("/upload/contentimg/{0}/",System.DateTime.Now.ToString("yyyyMMdd"));
string fileName=GenerateFileName()+Path.GetExtension(urlPath);
WebRequest request = WebRequest.Create(urlPath);
//使用默认验证
request.Credentials = CredentialCache.DefaultCredentials;
if (!Directory.Exists(serverPath + filePath)) { Directory.CreateDirectory(serverPath + filePath); }
string folderName =filePath + fileName;
System.Drawing.Image image = System.Drawing.Image.FromStream(request.GetResponse().GetResponseStream());
image.Save(serverPath+folderName);
image.Dispose();
return folderName;
}
注意:使用WebRequest 需要引用system.net空间
model.Content:FCK编辑器中的内容
/// <summary>
/// 增加一条数据
/// </summary>
public int Add( NewsEntity model )
{
//未添加图片说明的添加说明
MatchCollection matchs = Regex.Matches(model.Content, "<img.*/?>(<img/>)?", RegexOptions.IgnoreCase);
Match filePath;
foreach (Match match in matchs)
{
model.Content = model.Content.Replace(match.Value, match.Value.Replace("alt=\"\"", "alt=\"" + model.Title + "\""));
//将远程包含http和不是chinayq.com服务器中的图片上传
filePath = Regex.Match(match.Value, @"(http)+.*(jpg|png|gif|jpeg)", RegexOptions.IgnoreCase);
if (filePath.Success && filePath.Value.IndexOf("chinayq.com") < 0)
{
model.Content = model.Content.Replace(filePath.Value, WebUtility.PicOperate.UploadHttpFile(filePath.Value.Replace("\"", "")));
}
}
return dal.Add(model);
}
#endregion
/// <summary>
/// 上传远程文件到本地服务器
/// </summary>
/// <param name="filePath">远程文件</param>
/// <returns></returns>
public static string UploadHttpFile(string urlPath)
{
string filePath =string.Format("/upload/contentimg/{0}/",System.DateTime.Now.ToString("yyyyMMdd"));
string fileName=GenerateFileName()+Path.GetExtension(urlPath);
WebRequest request = WebRequest.Create(urlPath);
//使用默认验证
request.Credentials = CredentialCache.DefaultCredentials;
if (!Directory.Exists(serverPath + filePath)) { Directory.CreateDirectory(serverPath + filePath); }
string folderName =filePath + fileName;
System.Drawing.Image image = System.Drawing.Image.FromStream(request.GetResponse().GetResponseStream());
image.Save(serverPath+folderName);
image.Dispose();
return folderName;
}
注意:使用WebRequest 需要引用system.net空间
model.Content:FCK编辑器中的内容
相关文章推荐
- 蚂蚁分类信息系统KindEditor编辑器增加远程图片自动上传到本地并加水印自动填写摘要内容
- web编辑器远程图片自动上传
- 远程图片自动按文件夹上传到服务器-默飞出品
- 百度ue编辑器关闭自动抓取远程图片
- 如何解决eWebEditor在线编辑器的远程自动上传功能不能使用的问题?
- 让博客园的编辑器自动上传外链图片
- 百度编辑器上传图片,去除自动生成的title
- 如何解决eWebEditor在线编辑器的远程自动上传功能不能使用的问题?
- 使用kindeditor来替换ecshop的fckeditor编辑器,让ecshop可以批量上传图片
- 如何解决eWebEditor在线编辑器的远程自动上传功能不能使用的问题?
- simditor编辑器,图片上传链接替换
- KindEditor粘贴时候自动上传远程图片(非本地)
- 远程图片自动按文件夹上传到服务器-默飞出品
- 远程图片自动上传到服务器
- 让博客园的编辑器自动上传外链图片
- 使用Activex插件复制剪贴板中的word或excel内容到web HTML编辑器并自动上传图片或文件
- kindeditor/ckeditor编辑器加+图片自动上传成功
- 百度编辑器批量上传图片自动排版
- kindeditor/ckeditor编辑器加+图片自动上传成功(源码下载)