|
Hi guys, I want to write to a file but i am getting this weird error message. Only my application is using the path1. It Seems like file is being used by other process. I couldn't figure it out who is using which of my function is using the file.
using (StreamWriter sw = new StreamWriter(path1,false,Encoding.UTF8 ))
{
sw.WriteLine(""+doc.body.innerHTML+"");
sw.Flush();
sw.Close();
}
at System.IO._Error.WinIOError(Int32 errorCode,string maybeFullPath)
at System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare Share,Int32BufferSize,fileOptions options, SeCURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy)
|
|
|
|
|
netJP12L,
I don't think you need to call sw.Close() since it is in a using block. Though, i might be wrong!
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Are you allowed to write to the path? Do you have permissions, where are you trying to write to?
And, sw doesn't need to be closed, a using block will automatically call the Dipose method on an object that implements IDispose, StreamWriter does.
|
|
|
|
|
Yes, I do have permissions. I am creating folders, subfolders and file dynimacally and writing to the file. Even removing of sw.close or using statments doesn't help. Is there anyway i can find out which thread is using the file.
|
|
|
|
|
|
|
Thanks for answering guys, So far no lucky but what a funny thing i just noticed is that when i run the function to write to the file it throws exception related to file is being used by other process but when i run it again it actually writes ....what's going on I got no idea. Are my codes running faster than CPU ...;)
|
|
|
|
|
Hmm,
there may be several reasons.
Do you still have call to the Close-method in the end of using block. I suggest that you keep it.
Another thing. Check from your project properties / debug tab, is "Enable the Visual Studio hosting process" checked? If it is, what happens if you uncheck it and run the application again?
Mika
|
|
|
|
|
Exactly, you got the cure for my app problem.....before when i used to run my app in debug mode i was noticing this myapp.vshost.exe started...since i uncheck it works like charm.... Feel like i am on the safe planet....gonna giving u 5
|
|
|
|
|
You're welcome
Mika
|
|
|
|
|
I want to set the attrib of any file and folder using C#.NET button click event.
(As like in DOS: "attrib C:\test +S")
I want to run above DOS command with my C#.NET button click.
|
|
|
|
|
File.SetAttributes("textfile1.txt", FileAttributes.ReadOnly);
Just a suggestion for future!!! Try to Google the question you are posting. I believe, most of the times you will get get the answer there itself.
|
|
|
|
|
Thanks for your solution.
It works fine.
Can you please tell me about “attrib C:\test +s +h”. both attrib simultaneously.
|
|
|
|
|
|
Member 2837615 wrote: Can you please tell me about “attrib C:\test +s +h”. both attrib simultaneously.
You will need to write it in two statements; specifying the attributes you want.
|
|
|
|
|
Read up on how to use the SetAtributes method. A quick google search shows how to use a combination of attributes in one method call.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
The Class of Process is used to execute the command of DOS.
This class provide a Filed to set attrib.
|
|
|
|
|
Hi to all,
I need to read bitmap file which is basically scanned sheet like answers sheet.
So tell me if anyone knows.
Its urgent.
|
|
|
|
|
krinaljariwala wrote: I need to read bitmap file which is basically scanned sheet like answers sheet
Do you want to read it as image or extract the text from it?
If latter is the case, this should work:
FileStream fs = File.OpenRead("Holiday.bmp");
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
MemoryStream ms = new MemoryStream(data);
Bitmap bmp = new Bitmap(ms);
|
|
|
|
|
Hi,
i have tried this but i have scanned an answer sheet of entrance test exam paper, n stored as image file so i want to read at which answer's line its option is selected.The image includes options like you have to choose one answer from 4.So i want find which option is selected.
|
|
|
|
|
studying would probably be easier, but you're going to need some kind of really cool OCR or image recog software, i've seen some articles on CP about it but cant remember what i was looking for at the time, i think one compared the color data of each pixel to try to find patterns, it may have even been looking for things that were circled. handwriting recognition software may help too.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Manas Bhardwaj wrote: If latter is the case, this should work:
former, not latter.
|
|
|
|
|
Hi I want to write a program to forward incoming tcp connections on port 22 on my computer to another address on the network (which happens to be 192.168.37.20) on the same port 22. Does anyone have any suggestion how I can do this?
|
|
|
|
|
NAT
why must it be a program?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
I need to write a simple windows service that will automatically forward connections on port 22 (SSH) to the other address. And i have found no easy way to do this in windows, nor have i found a freeware program that can be installed as a system service
|
|
|
|