Click here to Skip to main content
15,906,558 members

Comments by Member 11968223 (Top 5 by date)

Member 11968223 12-Jan-17 11:06am View    
Yes. Thank you. Could you please answer my question.
Member 11968223 12-Jan-17 10:17am View    
No that was my mistake. Actually i want to SharePoint 2007 Add-in in Visual Studio 2015. Not SDK. My apologies.
Member 11968223 12-Jan-17 9:11am View    
Hi,
Thanks for your reply, your link which says "We are sorry, the page you requested cannot be found". May i know the issue.
Member 11968223 8-Dec-16 4:03am View    
Thank you
Member 11968223 1-Dec-16 8:29am View    
Below is the code for converting word files to pdf. In my client location this application is working fine for single user. They are using this app in citrix server. It is working for only single user. But it should work for 15 users at a time.

Error is : Word file is being used by another user.

They are not able to convert the word file to pdf for 15 users at a time.

Please let me know if you need any further information.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using iTextSharp.text;
using iTextSharp.text.pdf;
using com.itextpdf.text.pdf;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using System.Data;
using System.ComponentModel;
using Microsoft.Office.Interop.Word;

namespace PDF_Generator
{
public partial class PDF_Generator : Form
{
string singleFilePath = string.Empty;
string singleFile = string.Empty;
string multiplefiles = string.Empty;
string sourcePdf;
OpenFileDialog x;

public PDF_Generator()
{
InitializeComponent();

}

#region Button_Click Events

private void btnGenerate_Click(object sender, EventArgs e)
{
try
{

int FileSize;

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
object Missing = System.Reflection.Missing.Value;
object filename = (Object)singleFile;

object refFalse = false;
object refTrue = true;

FileInfo f = new FileInfo(singleFile);
FileSize = Convert.ToInt32(f.Length);

if ((f.Length / (1024 * 1024)) > 10)
{
MessageBox.Show("File size is more than 10MB. Please do not close the window.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

string selectedFileName = Path.GetFileNameWithoutExtension(singleFile) + ".pdf";

Object process = (Object)Convert.ToString(txtSelectDestination.Text) + "\\" + selectedFileName;
object fileFormat = WdSaveFormat.wdFormatPDF;
string ext = System.IO.Path.GetExtension(singleFile);

try
{
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filename, ref refFalse, ref refTrue, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);


btnGenerate.Enabled = true;
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed = 50;
Cursor.Current = Cursors.WaitCursor;

doc.SaveAs(ref process, ref fileFormat, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);

object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref Missing, ref Missing);
doc = null;

((_Application)word).Quit(ref Missing, ref Missing, ref Missing);
word = null;
sourcePdf = txtSelectDestination.Text + "\\" + selectedFileName;

string Password = txtProtectedPass.Text;

string InputFile = sourcePdf;

string OutputFile = @txtSelectDestination.Text + "\\" + " " + selectedFileName;

if (txtProtectedPass.Text != "")
{
using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfReader reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, Password, Password, PdfWriter.ALLOW_SCREENREADERS);
}
}
File.Delete(sourcePdf);
}

Cursor.Current = Cursors.AppStarting;

txtProtectedPass.Text = "";
txtProtectedPass.Focus();
}
}
}
}