PLease help getting error as The process cannot access the file 'D:\Inventracksys\Inv

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imranabdulaziz
    New Member
    • Dec 2006
    • 29

    PLease help getting error as The process cannot access the file 'D:\Inventracksys\Inv

    Dear All,
    I am making web application using Asp.net C#(Visual Studio2005). And Sql server 2005 as a back End
    I generated local mode report but as there was no printing option available . I assign printing feature to button click by exporting the data to EMF format and print
    Now when I run it through IDE VS2005 then it does not show any error.
    But when I run in through IIS in intranet it showing me this error

    The process cannot access the file 'D:\Inventracks ys\Inventorytra cking Vendorwiserepor t_1.emf' because it is being used by another process
    Where I am going wrong please guide me.
    Code used are
    Button click code
    protected void Btnprint_Click( object sender, EventArgs e)
    {
    LocalReport report = new LocalReport();
    vw_tranTableAda pter da = new vw_tranTableAda pter();
    report.ReportPa th = @"D:\Inventrack sys\inventorytr acking\Vendorwi sereport.rdlc";
    report.DataSour ces.Add(new ReportDataSourc e("tran_vw_tran ", da.GetDataByven dor(RadioButton List1.SelectedV alue, DropDownListven dor.SelectedVal ue)));
    export(report);
    m_currentpagein dex = 0;
    Print();
    }

    Creating stream as
    private Stream CreateStream(st ring name, string filenameextensi on, Encoding encoding, string mimetype, bool willseek)
    {
    Stream stream = new FileStream(@"D: \Inventracksys\ Inventorytracki ng " + name + "." + filenameextensi on, FileMode.Create );
    //Stream stream = new FileStream(name + "." + filenameextensi on, FileMode.Create );
    m_streams.Add(s tream);
    return stream;
    }

    Exporting to EMF

    private void export(LocalRep ort report)
    {
    string deviceInfo = "<DeviceInf o>" + " <OutputFormat>E MF</OutputFormat>" + " <PageWidth>9i n</PageWidth>" + " <PageHeight>12i n</PageHeight>" + " <MarginTop>0.25 in</MarginTop>" + " <MarginLeft>0.2 5in</MarginLeft>" + " <MarginRight>0. 25in</MarginRight>" + " <MarginBottom>0 .25in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; m_streams = new List<Stream>(); report.Render(" Image", deviceInfo, CreateStream, out warnings);
    foreach (Stream stream in m_streams) stream.Position = 0;

    }
    Printhandler event


    private void PrintPage(objec t sender, PrintPageEventA rgs ev)
    {
    Metafile pageImage = new
    Metafile(m_stre ams[m_currentpagein dex ]);
    ev.Graphics.Dra wImage(pageImag e , ev.PageBounds);
    m_currentpagein dex++;
    ev.HasMorePages = (m_currentpagei ndex < m_streams.Count ); }

    printing option


    private void Print()
    {
    const string printerName =
    "Microsoft Office Document Image Writer";
    if (m_streams == null || m_streams.Count == 0)
    return;
    PrintDocument printDoc = new PrintDocument() ;
    printDoc.Defaul tPageSettings.L andscape = true;
    printDoc.Printe rSettings.Print erName = printerName;
    // lblerrmsg.Text = printDoc.Printe rSettings.Print erName;


    if (!printDoc.Prin terSettings.IsV alid)
    {
    string msg = String.Format(
    "Can't find printer \"{0}\".", printerName);
    //MessageBox.Show (msg, "Print Error");
    lblerrmsg.Text = "Print Error";
    return;
    }

    printDoc.PrintP age += new PrintPageEventH andler(PrintPag e);
    printDoc.Print( );
    }
    public void Dispose()
    {
    if (m_streams != null)
    {
    foreach (Stream stream in m_streams)
    stream.Close();
    m_streams = null;
    }
    }

    Now when I run it through IDE VS2005 then it does not show any error.
    But when I run in through IIS in intranet it showing me this error

    The process cannot access the file 'D:\Inventracks ys\Inventorytra cking Vendorwiserepor t_1.emf' because it is being used by another process
    Where I am going wrong please guide me.
    Thanks
Working...