Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6787985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:25:52+00:00 2026-05-26T17:25:52+00:00

I have a vb.net MVC3 Razor app that generates PDF files. The problem is

  • 0

I have a vb.net MVC3 Razor app that generates PDF files. The problem is that if 2 seperate users click the print button at the same time it throws the following exception..:

  The process cannot access the file 'E:\web\xxxxxxxxxxsonl\PDF_Files\MailingLables.pdf' because it is being used by another process. 

  All of the controller actions to do with printing are basically like below:

 Function Ind_Cert(ByVal firstName As String, ByVal lastname As String, ByVal classRef As String)
        Dim _Attendance As attendance = db.attendances.Where(Function(f) f.Completed_Class = "Completed" And f.firstName = firstName And f.lastName = lastname).FirstOrDefault
        If Not IsNothing(_Attendance) Then
            Dim _reg_classes As List(Of reg_classes) = db.reg_classes.ToList
            Dim _registrants As List(Of reg_info) = db.reg_info.ToList
            Dim _courses As List(Of cours) = db.courses.ToList
            Dim _Board As List(Of board_members) = db.board_members.ToList
            Dim Board_Member As board_members = _Board.Where(Function(f) f.Official_Cap = "xxxxxx President").FirstOrDefault
            Dim RecordId As Integer = 0
            Dim conf_info As conf_info = db.conf_info.Single(Function(r) r.id = 0)
            Dim conf_num As Integer = conf_info.conf_number
            Dim _conf_num As String = conf_num.ToString
            Dim Length As Integer
            Dim _prefix As String = String.Empty

            If Str(conf_num) <> "" Then
                Length = Str(conf_num).Length
            End If


            Dim Divisor As Integer = 10 ^ (Length - 1)
            Dim conf_num_start As Integer = 0
            Dim Digits(Length - 1) As Integer

            While (conf_num > 10)

                'Extract the first digit
                Digits(conf_num_start) = Int(conf_num / Divisor)

                'Extract remainder number - and store it back in Num
                conf_num = conf_num Mod Divisor

                'Decrease Divisor's value by 1/10th units
                Divisor /= 10

                'Increment Index
                conf_num_start += 1

            End While


            If conf_num = 0 Or 4 Or 5 Or 6 Or 7 Or 8 Or 9 Then _prefix = "th"
            If conf_num = 1 Then _prefix = "st"
            If conf_num = 2 Then _prefix = "nd"
            If conf_num = 3 Then _prefix = "rd"




            Dim pdfpath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
            Dim imagepath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
            Dim _PdfName As String = "Cert_" + lastname + ".pdf"
            Dim doc As New Document
            doc.SetPageSize(iTextSharp.text.PageSize.LETTER.Rotate())
            doc.SetMargins(1, 1, 1, 1)
            Dim _pageCounter As Integer = 0

            Dim Californian As BaseFont = BaseFont.CreateFont(Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\Fonts\" + "CALIFB.TTF", BaseFont.CP1252, BaseFont.EMBEDDED)
            Dim Copper As BaseFont = BaseFont.CreateFont(Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\Fonts\" + "COPRGTB.TTF", BaseFont.CP1252, BaseFont.EMBEDDED)
            Dim Bold_Times As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, False)
            Dim BF_Times As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, False)
            Dim F_Name As New Font(BF_Times, 16, Font.BOLD, BaseColor.BLACK)
            Dim _Parking_Name As New Font(BF_Times, 18, Font.NORMAL, BaseColor.BLACK)
            Dim _Parking_Date As New Font(BF_Times, 24, Font.BOLD, BaseColor.BLACK)

            '**********************************Y lines for trial***********************************
            Dim y_line1 As Integer = 670
            Dim _Counter As Integer = 1
            Dim _Page As String = 1





            Dim _CertJpg As Image = Image.GetInstance(imagepath + "/cert.jpg")
            Dim imageWidth As Decimal = _CertJpg.Width
            Dim imageHeight As Decimal = _CertJpg.Height
            Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdfpath + _PdfName, FileMode.Create))
            doc.Open()
            Dim cb As PdfContentByte = writer.DirectContent


            If _Attendance.Completed_Class = "Completed" Then

                Dim _confInfo As conf_info = db.conf_info.Single(Function(a) a.id = 0)
                Dim year As String = Right(_confInfo.conf_start_date, 4)
                Dim _reg As reg_info = db.reg_info.Single(Function(b) b.id = _Attendance.reg_id)
                Dim name As String = _reg.first_name + " " + _reg.last_name
                Dim _dates As String = _confInfo.conf_start_date + " - " + _confInfo.conf_end_date
                Dim _course As cours = db.courses.Single(Function(c) c.course_ref = _Attendance.course_ref)
                Dim _className As String = _course.course_title.ToString
                Dim _hours As String = _course.course_hours
                Dim _certName As String = Board_Member.First_Name + " " + Board_Member.last_name


                _CertJpg.Alignment = iTextSharp.text.Image.UNDERLYING
                _CertJpg.ScaleToFit(792, 611)
                doc.Add(_CertJpg)

                cb.BeginText()
                cb.SetFontAndSize(Californian, 36)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "CERTIFICATE OF COMPLETION", 396, 397.91, 0)
                cb.SetFontAndSize(Bold_Times, 22)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, name, 396, 322.35, 0)
                cb.SetFontAndSize(Bold_Times, 16)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _hours + " Hours", 297.05, 285.44, 0)
                cb.SetFontAndSize(Bold_Times, 16)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _dates, 494.95, 285.44, 0)
                cb.SetFontAndSize(Bold_Times, 16)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Class Attended: " + " " + _Attendance.course_ref + " -- " + _className, 396, 230.34, 0)
                cb.SetFontAndSize(Copper, 16)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _conf_num + _prefix + " Annual Conference " + _dates, 396, 193.89, 0)
                cb.SetFontAndSize(Bold_Times, 13)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _certName, 396, 175.69, 0)
                cb.SetFontAndSize(Bold_Times, 10)
                cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "xxxxxxx President", 396, 162.64, 0)
                cb.EndText()

            End If

            doc.Close()
            Return _PdfName
        Else
            Return "Fail"
        End If


    End Function

This error happens like I said any time 2 users try to generate a PDF file at the same time. Anyone know of a fix for this issue? Google has turned up countless pages about someone can’t delete a file in windows because its being used. But that isn’t much help.. Any ideas???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:25:52+00:00Added an answer on May 26, 2026 at 5:25 pm

    You can pretty much do two things.

    1. Add a lock on the file and block the second (and third and fourth, etc) until the lock is cleared

    2. Create a unique file for each instance.

    I’d recommend #2. You can keep the same file name, just put the file in a unique directory. A GUID is usually the easiest for me:

    Dim pdfpath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
    pdfPath = Path.Combine(pdfPath, Guid.NewGuid.ToString())
    Directory.CreateDirectory(pdfPath)
    

    Then change your return to include the path created above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With ASP.NET MVC3 (Razor) I have a simple page that loads a jQuery UI
I have an asp.net mvc3 Razor app being developed in VS2010 using Git for
I have to develop an ASP.NET MVC3 application in C# and Razor that has
I had created a webpage using asp.net mvc3 razor. I have two master pages
I have a string created using asp.net MVC3 Razor block like this: @{ var
I have online form builder appplication in ASP.NET MVC3 with Razor views. It is
Here's the issue at hand: I have developed an ASP.NET MVC3 application using Razor.
I have an href in my asp.net MVC3 Razor view and I want to
I have built an ASP.NET MVC 3 web application (with exlusively Razor/cshtml pages) that
I am working on a project which adopted ASP.NET MVC3(Razor) tech. Now, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.