我为另一个团队编写了一个实用程序,它递归地浏览文件夹,并使用Word Interop和C#将发现的Word文档转换为PDF.
我们遇到的问题是文档是使用日期字段创建的,这些日期字段在保存之前更新到今天的日期.我找到了一种在打印前禁用更新字段的方法,但我需要阻止字段在打开时更新.
那可能吗?我想在C#中修复,但如果我必须做一个Word宏,我可以.
我一直在阅读视图模型和复选框上的各种帖子,但我的大脑开始锁定,我需要向正确的方向推进一点.
这是我的简化视图模型.我有复选框需要用它们的值填充列表.我不认为这可以自动发生.我不确定如何正确地弥合字符串值数组和List之间的差距.建议?
public int AlertId { get; set; }
public List<int> UserChannelIds { get; set; }
public List<int> SharedChannelIds { get; set; }
public List<int> SelectedDays { get; set; }
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Web API服务.我正在尝试通过GET请求进行文件下载.这个方法发射得很好并且达到了我的突破点.我创建一个响应并返回它.然后,奇怪的是,断点再次命中.我正在使用Firefox附加海报来测试它.海报说服务器没有回应.知道为什么会这样吗?
这是响应创建代码:
HttpResponseMessage result = this.Request.CreateResponse(HttpStatusCode.OK);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentLength = file.Length;
result.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddDays(-1));
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("Attachment") { FileName = file.Name };
return result;
Run Code Online (Sandbox Code Playgroud)
唯一重要的变化(我能想到的)是我的WebApiConfig,如下所示:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
Run Code Online (Sandbox Code Playgroud)
我的方法签名如下所示:public HttpResponseMessage GetUpdate(int Id)
我所有的其他行动都很好.我是否在客户端丢失了某些内容,比如接受标题或其他内容?我现在正在做一个简单的GET.
谢谢!
我有一些Web API代码,我从SO帖子和其他网站汇编.然而,任务的东西对我来说仍然是新的.我正在尝试将上传的文件复制到新位置,但有时(并非所有时间)我在尝试复制文件时遇到异常.该异常表示该文件正由另一个进程使用.但是,每次都不会发生这种情况.我想我需要在其他地方移动复制操作.这是我的代码.有什么建议?
var provider = new MultipartFormDataStreamProvider(uploadroot);
var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>(t =>
{
if (t.IsFaulted || t.IsCanceled)
throw new HttpResponseException(HttpStatusCode.InternalServerError);
var docConversionId = Guid.NewGuid().ToString("N");
var sourceFilePath = Path.Combine(uploadroot, provider.FileData.First().LocalFileName);
var destinationFilePath = Path.Combine(inboxroot, docConversionId);
File.Copy(sourceFilePath, destinationFilePath);
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(docConversionId);
//response.Content.Headers.Add("DocumentConversionId", docConversionId);
return response;
});
return task;
Run Code Online (Sandbox Code Playgroud) 我的团队最近对Web API服务进行了重构,以将一些重复代码移入静态方法。一种方法与从请求中提取上载的文件有关。该方法可用于单元测试,但在负载下会引发异常。在SO帖子中找到了部分代码,但总的来说,我担心我们没有正确使用它。这是代码:
internal static string ExtractFile(HttpRequestMessage request)
{
if (request.Content.IsMimeMultipartContent())
{
string uploadRoot = ServiceHelper.GetUploadDirectoryPath();
var provider = new MultipartFormDataStreamProvider(uploadRoot);
try
{
Task.Factory
.StartNew(() => provider = request.Content.ReadAsMultipartAsync(provider).Result,
CancellationToken.None,
TaskCreationOptions.LongRunning, // guarantees separate thread
TaskScheduler.Default)
.Wait();
}
catch(System.AggregateException ae)
{
if(log.IsErrorEnabled)
{
foreach(var ex in ae.InnerExceptions)
{
log.Error("ReadAsMultipartAsync task error.", ex);
}
}
var errorResponse = request.CreateErrorResponse(HttpStatusCode.InternalServerError, "An error occurred while extracting the uploaded file from the request.");
throw new HttpResponseException(errorResponse);
}
var fileData = provider.FileData.First();
var localName = fileData.LocalFileName; …Run Code Online (Sandbox Code Playgroud) 当页面呈现时,如何阻止ASP.Net对List Items中的锚标记进行编码?
我有一组对象.每个对象都有一个link属性.我做了一个foreach并尝试输出BulletedList中的链接,但ASP编码了所有链接.
任何的想法?谢谢!
这是令人讨厌的代码片段.当用户选择专业时,我使用SelectedIndexChange事件清除并添加到BulletedList的链接:
if (SpecialtyList.SelectedIndex > 0)
{
PhysicianLinks.Items.Clear();
foreach (Physician doc in docs)
{
if (doc.Specialties.Contains(SpecialtyList.SelectedValue))
{
PhysicianLinks.Items.Add(new ListItem("<a href=\"" + doc.Link + "\">" + doc.FullName + "</a>"));
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有(或将有;它尚未编写)一个 .NET Web API 控制器方法,我将要返回一个整数列表作为 JSON 响应。在客户端,我只想将整数反序列化为列表。我尝试使用 { [1,2,3,4] },但这显然不是有效的 JSON。如果我执行 { "ids" : [1,2,3,4] },它不会反序列化为一个简单的列表。我知道我可以为此创建一个超级简单的类,但我希望避免这种情况。有解决方案吗?谢谢!
var ids = JsonConvert.DeserializeObject<List<int>>(jsonResult1);
Run Code Online (Sandbox Code Playgroud)