Upload multiple pdf files to server using excel template? - c#

I have list of pdf file url in excel template Now i want to upload all files from my local pc to server just by browsing the excel file and click to upload.
I have achieved this task by using iTextSharp Library pdfreader and pdfstamper class, but what problem is, i need to read all files by using pdfreader.
Case may come, when some of pdf files are encrypted, So i can not able to read that file using pdfreader of itextsharp and not be able to upload the same.
Is it possible that without reading the pdf file i can just dumped it to server just like what Fileupload.Saveas method does????

Related

Change what file an Outlook attachment points to

For instance, I have a word document as an Outlook attachment. I want to have a C# program that will find that file's local location, process it into a PDF, and then change the email's attachment to that new PDF file. The next time that attachment is opened, it will open the PDF and not the word document.
Edit 1: The email attachment is in my inbox, as someone has sent this file to me. I am able to edit the actual word file just like any other document just fine. I figure this would be possible by adding
Is this function possible? and remoreceived chments to existing recieved emails as well.
Yes, that is possible. You can develop an Outlook COM add-in (for example, a VSTO based one). The Attachment class provides the SaveAsFile method which saves the attachment to the specified path. Then you can automate Word where you may open the file just saved and re-save it using the .pdf file format. Or you may consider using third-party components that don't require Word installed on the system. After converting the document and getting the required pdf file you may remove an old attachment and re-add a new one. The Attachments.Add creates a new attachment in the Attachments collection.
You may find the following articles helpful:
Attach a File to a Mail Item
Modify an Attachment of an Outlook Email Message
How To: Add an attachment to an Outlook e-mail message

How to download Excel file from website using C# desktop application

I tried to use few method to download 1 excel file from website
I tried to use WebClient and DownloadFile... but it return 400 bad
request
I tried to use File.WriteAllBytes also kick in exception
My current workaround is call IExplorer with that particular file path ..then it will start to download(after user select file path)
Is that any way that i can straight download excel file without any notification?
Sample Excel Link: https://example.com/sr/XXX.issueviews:searchrequest-excel-all-fields/12345/SearchRequest-12345.xls?tempMax=1000

Determine what user account iTextSharp runs as

I have a website where users can upload PDF files and I then parse them using iTextSharp.
The uploaded files are saved to a network share without a problem. I then pass the file path of the newly saved file to iTextSharp:
pdfReader = new PdfReader(fileName);
But I get:
Error: \\networkshare\savedPDF.pdf not found as file or resource. File: \\networkshare\savedPDF.pdf
Looking at the source code I see that it was not able to get the file stream:
inp = BaseFont.GetResourceStream(filePath);
if (inp == null)
throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filePath));
Since this code works fine on my machine and the file does exist, I can only assume that it is a permissions issue. This issue is only present in production.
How can I determine/set the user that the component runs as?

Word File savings without closing are Not Uploaded to the server

In my case, I want to build my own "drop box" like application which I am going to use as a part of my another project.
Discription:
When a word file is opened in the "drop box" folder(inside the folder where changes to the files, file creations deletions ect.. are identified). pictures, txts, txt updates are uploaded to the server without any issue.
But when it comes to office documents. office document creation is uploaded.
Problem:
when the word file is opened, and do some update and save it. the file can not be uploaded due to permission error. even the opened file can not be copied to another place and then uploaded.
Any one faced this kind of issue, and any sugessions.
But we can manually copy and save a opened and saved(but not closed) to another location
But in the program it is not allowed.
You can create another copy of file, this is important because uploading may be slower and reading shared file may lead to conflicts for Word, so what you can do is, you can create a copy quickly on temp file and upload the temp file.
string tmp = Path.GetTempFileName();
using(Stream s = new FileStream(filePath,
FileMode.Open, FileAccess.Read,
// following option will let you open
// opened file by other process
FileShare.ReadWrite)){
using(FileStream fs = File.OpenWrite(tmp)){
// this will copy file to tmp
s.CopyTo(fs);
}
}
// upload tmp file...
your problem is similar to what we faced. In our case we are all connected to a domain directory and the problem was the antivirus installed on our server gives read/write permissions to users (executing exe, installing apps). so you specifically need to give a user the right to execute an app that wants to use another app, in this case office docs.
The problem extended to asp apps using Crystal Reports. hope it helps.

System.IO.FileMode.Open

For my system, i first need to read CSV file and then i need to connect to the database in SQL server 2008 according to the data in .ini file.
I use System.IO.FileStream() to read file. There is no problem to open and read data.
But, when i read csv file and then connect to the database , i cant access to the .ini file
because System.IO.FileStream() function take the path of ini file like as the location of csv file.
So, when i read csv file from Desktop , System.IO.FileStream() function search the ini file in Desktop and when i read from My Document, it search in My Document.
Thus, i want to know how to control this.
My function to read ini file : System.IO.FileStream("fileNameOnly", System.IO.FileMode.Open, System.IO.FileAccess.Read);
You can set your OpenFileDialog.RestoreDirectory to True to have the dialog reset its location on each use.

Categories

Resources