Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have developed one win forms application which is for converting word documents to PDF files. I have sent the application to clients. It is working for single user only, not working for multiple users.

Could you please help me with this issue.

Thanks,

Regards,
Sudhakar Chitlam

What I have tried:

Windows form applications for multiple users
Posted
Updated 1-Dec-16 2:27am
Comments
OriginalGriff 1-Dec-16 7:05am    
What does "not working for multiple users" mean?
What does it do that you didn't expect, or not do that you did?


Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Member 11968223 1-Dec-16 8:29am    
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();
}
}
}
}
Dave Kreskowiak 1-Dec-16 11:00am    
Your client has to setup Citrix to run your application the same as if it was an Office application. Your app is entirely dependent on Office. Since Office normally only runs a single instance of an executable, like Word.exe or Excel.exe, on a machine, it won't work for multiple users on the same machine. Special consideration have to be in place in Citrix to allow multiple people to run multiple Office applications at the same time, each user having it's own instance of the executable running. The same has to be applied to your application.

There is nothing to do in your code to fix this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900