Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi In web application i will create .dll file ,and in next code i will try to open that file ,but it show error "Unable to access this file,bcz this file used by another process wp3w.exe "

I am create file using below code

VB
File.Create(workingDirctory & "\sample.dll")

    If File.Exists(workingDirctory & "\sample.dll") Then 'If code reach here it show error
           strMFPList = File.ReadAllText(workingDirctory & "\sample.dll")
           MFPList = Split(strMFPList, vbCrLf, -1, CompareMethod.Text)
           If Not Trim(strMFPList) = "" Then
               strMFPList = strMFPList & vbCrLf
           End If
       End If


In above code,in first line i will create .dll file,in second line i will try to read that file,but is show error(above i mention) in if condition.

But if file is already there,then can read file,

Why if create and same time try to read it show error like that ? need to close files stream ? anything ?


Regards
Aravind
Posted
Updated 12-Jan-15 18:20pm
v2

 
Share this answer
 
File.Create returns a FileStream. you need to close/dispose it before open file again
try with
VB
File.Create(workingDirctory & "\sample.dll").Close()

or
VB
Using fs as FileStream = File.Create(workingDirctory & "\sample.dll"
End Using
 
Share this answer
 
v2
Comments
Aravindba 13-Jan-15 6:12am    
Thank u for ur reply, First one not work,second work fine,for create time use
Using fs as FileStream = File.Create(workingDirctory & "\sample.dll"
End Using

For read file and write some text on file,that time it not show any error ? i mean it not show "used by another process " ?
After read and write how to close file stream.
Just i ask question,tomorrow i will check after read and write any text on dll file

Thanks a lot.

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