简体   繁体   English

itextsharp-将文件保存到远程服务器

[英]itextsharp - saving file to remote server

how can I save .pdf file to remote server? 如何将.pdf文件保存到远程服务器? what to change at below code part? 下面的代码部分要更改什么?

if (File.Exists(@"C:\\Users\\xxx\\xxx.pdf"))
{
    MessageBox.Show("xx.", "xx");
}
else
{
    Directory.CreateDirectory(@"C:\\Users\\xx);
    PdfWriter.GetInstance(pdfDosya, new FileStream(@"C:\\Users\\xx\\xx.pdf", FileMode.Create));
}

Confirm you can view the place you are looking to save to. 确认您可以查看要保存到的位置。 Then update your code 然后更新您的代码

String serverLocation = @"\\servername\";

if (File.Exists(serverLocation +@"Users\xxx\xxx.pdf"))
{
    MessageBox.Show("xx.", "xx");
}
else
{
    Directory.CreateDirectory(serverLocation +@"Users\xx);
    PdfWriter.GetInstance(pdfDosya, new FileStream(serverLocation +@"Users\xx\xx.pdf", FileMode.Create));
}

As mentioned in comments, when you use @ you do not need to escape your \\'s. 如评论中所述,当您使用@时,不需要转义\\。

Probably, the only difference would be your authentication into the server before save any file. 可能唯一的区别是您在保存任何文件之前向服务器进行身份验证。

The easiest way to do that, would be using "User Impersonation". 最简单的方法是使用“用户模拟”。

Install it in your application 将其安装在您的应用程序中

https://www.nuget.org/packages/UserImpersonation/ https://www.nuget.org/packages/UserImpersonation/

Install-Package UserImpersonation -Version 1.0.0 安装包UserImpersonation-版本1.0.0

A Quick example with "User Impersonation DLL" 一个带有“用户模拟DLL”的快速示例

using (UserImpersonation obj = new UserImpersonation("YourUserNameToAccessTheServer", "YourDomain", "UserPassword"))
{
   string YourDirectoryFullNameExample = "\\ServerName\\Folder1\\Folder2\\File.Pdf"
   if (File.Exists(YourDirectoryFullNameExample))
   {
      MessageBox.Show("xx.", "xx");
   }
   else
   {
      Directory.CreateDirectory(@"YourDirectoryFullNameExample);
      PdfWriter.GetInstance(pdfDosya, new FileStream(YourDirectoryFullNameExample, FileMode.Create));
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM