进程无法访问文件“\ path”因为这是另一个过程

编程入门 行业动态 更新时间:2024-10-25 03:23:26
本文介绍了进程无法访问文件“\ path”因为这是另一个过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的项目中,我正在访问文件本地文件并将其复制到另一个文件,然后对其进行水印,但在复制时我收到IO异常无法访问文件我的代码可以告诉我什么是问题,

Hi, In my Project I am accessing a file local file and copying it to another file then watermarking it, but while copying I am getting the IO Exception "Can’t Access the file" can any body tell me what would be the problem is my code is,

protected void AddWaterMark(string file) { string watermark = "Confidential Document Printed on " + DateTime.Now.ToString(); const int emSize = 40; try { // Get a fresh copy of the sample PDF file string filename = @"E:\Rajesh_Kumar\Application\Valuation\ExamManagement\ExamManagement\FileUpload\"+file; string filename1 =@"E:\Rajesh_Kumar\Application\Valuation\ExamManagement\ExamManagement\FileUpload\" + file; ; bool b = true;// File_lock(filename); if(b==true) { File.Copy(Path.Combine(@"E:\Rajesh_Kumar\Application\Valuation\ExamManagement\ExamManagement\Uploads", filename), Path.Combine(@"E:\Rajesh_Kumar\Application\Valuation\ExamManagement\ExamManagement\Uploads ", filename1), true); // Create the font for drawing the watermark XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic); // Open an existing document for editing and loop through its pages PdfDocument document = PdfReader.Open(filename); // Set version to PDF 1.4 (Acrobat 5) because we use transparency. if (document.Version < 14) document.Version = 14; for (int idx = 0; idx < document.Pages.Count; idx++) { //if (idx == 1) break; PdfPage page = document.Pages[idx]; // Variation 1: Draw watermark as text string // Get an XGraphics object for drawing beneath the existing content XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend); // Get the size (in point) of the text XSize size = gfx.MeasureString(watermark, font); // Define a rotation transformation at the center of the page gfx.TranslateTransform(page.Width / 2, page.Height / 2); gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI); gfx.TranslateTransform(-page.Width / 2, -page.Height / 2); // Create a string format XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Near; format.LineAlignment = XLineAlignment.Near; // Create a dimmed red brush XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0)); // Draw the string gfx.DrawString(watermark, font, brush, new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),format); } // Save the document... document.Save(filename); // ...and start a viewer Process.Start(filename); File.Exists(filename); } } catch(Exception ex) { ClientMessaging(ex.Message); } }

推荐答案

你好, 请在打开文档前关闭文档。例如 Hello, Please close your document before open it. e.g. // Save the document... document.Save(filename); //Close the document document.Close(filename); // ...and start a viewer Process.Start(filename);

谢谢

Thanks

更多推荐

进程无法访问文件“\ path”因为这是另一个过程

本文发布于:2023-11-04 12:18:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:这是   无法访问   进程   过程   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!