|
Hi,
After loading an image file in a picturebox with picturebox.Image = Image.FromFile(Foto.Path) i want the file deleted from the hard disk.
First I dispose the image in the picturebox (picturebox.Image.Dispose()) an then I delete teh file (System.IO.File.Delete(Foto.Path))
I recieve the message acces denied
Can anybody help me
Thnks
Jo De Decker
|
|
|
|
|
The Image object that you originally used to load the image from the file still has the file open. You called .Dispose() on the Image object in the picturebox, not on the Image object that loaded the file.
To work around this little "feature", see this[^] article on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
While testing a service we've setup in Visual Studio / VB.NET we've found that the service will start without a problem if the files that it is monitoring are local to the machine the service is running on.
As soon as we try to monitor a file on our network, and start the service, the following security message is thrown:
Service cannot be started. System.UnauthorizedAccessException: Access to the path "\\TheServer\D Drive\FTP Files\OpenActions.csv" is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.GetLastWriteTimeUtc(String path)
at System.IO.File.GetLastWriteTime(String path)
at FileChangeMonitor.ChangeMonitor.CheckFileChanged(String FileName, DateTime& LastChangeDate) in E:\_MyFiles\Vb.NetProjects\Development\FileChangeMonitor\FileChangeMonitor\ChangeMonitor.vb:line 171
Any suggestions on what needs to be changed via security is appreciated.
Lost in the vast sea of .NET
|
|
|
|
|
By default services run under the SYSTEM account. That wont have any rights to access files on the network. Each service can be configured seperatly. This can be done under Control Panel->Administration->Services->Right Click->Properties->LogOn (Im not sure about the names because Im using a german windows version).
|
|
|
|
|
That worked... Thanks!!
Lost in the vast sea of .NET
|
|
|
|
|
A second problem your going to run into is that the FTP server will not lock the file that is being uploaded to it. Your service has to take into account that it cannot know when the file is completely written to the disk by the FTP server. The FileWatcher will notify you when the file is created, not when it is closed by the FTP Server.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You brought up a very good question. How do we know if a file that we're looking for with the service is closed by the FTP process? I'm not sure what the answer is? Any suggestions?
Lost in the vast sea of .NET
|
|
|
|
|
The short answer is, you can't.
Most FTP server implementations (and I can't tell you which ones do and don't do this) don't lock the files they are writing for exclusive write access. This means that you can open the file while the FTP server is writing it.
You can not open the file for exclusive (not shared) access while you read the file, because this might have the affect of forcing the FTP server to abort the transfer when it can no longer write to the file.
Other that testing for exclusive read access, there is no way to find out when the file is completely written.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need to get the date to show in something such as a textbox or whatever. But everything I try doesn't show the date. I set the textbox to read only and everything. i am using ;
<br />
Dim D As Date<br />
D = Today<br />
TextBox7.Show()<br />
can anyone help me?
thanx
|
|
|
|
|
try -
textbox.text = d.tostring()
|
|
|
|
|
Hey, i am trying to figure out why ReadFile isn't working the way it should in VB.NET. The problem is that I call ReadFile on some file that i open with CreateFile, and it fills a buffer with the first couple of bytes from the file.. that is fine. but when i call ReadFile again, it still returns the same first bytes.. as if it didnt increment the file pointer. Then, i tried checking the file pointer value before and after each call to readfile.. and what seems to happen is that every time readfile is called, the file pointer is reset to 0, because after the first, or second call to readfile the file pointer is correct (the number of bytes i read using the function).. so i guess it gets reset to 0 before it fills the buffer.
here is the code if anyone can help:
<br />
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer<br />
<br />
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer<br />
<br />
Declare Function ReadFile Lib "kernel32" (ByVal hFile As Integer, ByVal destBuffer() As Byte, ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer, ByRef lpOverlapped As OVERLAPPED) As Integer<br />
<br />
...
<br />
<br />
Dim hDisk As Integer<br />
Dim bytesReturned As Integer<br />
<br />
hDisk = CreateFile("E:\somebigfile.dat", _<br />
GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, _<br />
Nothing, OPEN_EXISTING, 0, 0)<br />
<br />
If hDisk = INVALID_HANDLE_VALUE Then Exit Sub<br />
<br />
me.Text = SetFilePointer(hDisk, 0, Nothing, FILE_CURRENT)<br />
<br />
Dim dest() As Byte<br />
ReDim dest(1023)<br />
Dim destLen As Integer = dest.Length<br />
<br />
ReadFile(hDisk, dest, 1024, bytesReturned, Nothing)<br />
PrintData(dest, txt1) 'just a function that writes the data to a textbox txt1<br />
<br />
me.Text &= " " & SetFilePointer(hDisk, 0, Nothing, FILE_CURRENT)<br />
<br />
ReadFile(hDisk, dest, 1024, bytesReturned, Nothing)<br />
PrintData(dest, txt2)<br />
<br />
me.Text &= " " & SetFilePointer(hDisk, 0, Nothing, FILE_CURRENT)<br />
<br />
ReadFile(hDisk, dest, 1024, bytesReturned, Nothing)<br />
PrintData(dest, txt3)<br />
Thank you for any help!!!! This is driving me nuts!!!
r -€
|
|
|
|
|
First, according to the MSDN docs on ReadFile, your buffer should be passed ByRef, not ByVal. Second, are you checking the value of bytesReturned after each read?
Why are you P/Invoking theres functions in the first place? They're wrapped by the System.IO namespace. Using the classes found there is MUCH easier than what your doing. I only say this because your posted code isn't doing anything that these classes couldn't handle.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well, the buffer is an array, which seems to automatically act as a pointer when it is passed to C functions, also I saw the declaration with ByVal many places and it seemed to work.
I checked bytesReturned after each call, it is 1024. I also tried clearing the array before each call to ReadFile, and it still fills the buffer each time with the first bytes of the file.
I realize now I can use the System.IO namespace and FileStream and such, but this has become more of a curiosity on my part. I am befuddled as to why API functions (I had similar problems calling ZLib DLL functions from VB.NET) don't work properly in VB.NET. Maybe it is something with the managed code heap or something?
Thank you for your reply, however.. if anyone finds anything more on the subject please let me know.
r -€
|
|
|
|
|
How to set the first parameter of URLDownlofToFIle() in VB.
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
I have created a dll ,which makes use of the urldownloadtofile win32 API.
This dll works fine from within VB.
But when I access it from ASP ..the urldownloadtofile function ..wont work ..
I supose it has got to do something with the first parameter :
pCaller
Pointer to the controlling IUnknown interface of the calling Microsoft ActiveX component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download.
Please help me out...
|
|
|
|
|
ASP/ASP.NET are server side technologies that generate HTML. From with an ASP/ASP.NET Page, the code will run under the account of the web server. This account usually DOES NOT have write permissions to the file system.
If you try and call this function from inside an ActiveX component running in a web page client-side, the same is true. Security restrictions will not allow the component to write to the file system on the client machine.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave !
Thanx for ur post.
Anyway ,My dll executes on the web server .Basically what I'm trying to achieve is save an html page on the server and then mail it some recepient ..
i'm in no way trying to save the page on the client m/c ..
thanx n reagrds.
Girija
|
|
|
|
|
Then the ASPNET account that your app is running under doesn't have Write permissions to the folder your trying to save your page to. Go into the Properties/Security tab of whatever folder your saving these pages to and check to see if ASPNET has Write permissions.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The code you submitted was a pike of commented out code, but I see one glaring problem with your URLDownloadToFile call:
DownloadFile = URLDownloadToFile(x, sSourceUrl, sLocalFile, BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS
The parameter where your passed the constant BINDF_GETNEWESTVERSION is reserved and must always be 0. The new line should read something like this: (NOT TESTED!)
DownloadFile = URLDownloadToFile(0, sSourceUrl, sLocalFile, 0, 0)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I want to dynamically add nodes to treeview control based on database values.
My database structure in MS-Access is as follows (first row is table columns and then follows the data rows):
MyID MyTitle ParentID
1 Root Title 0 'This is the root
2 Title 1 1 '1 indicates it is child to row where MyID=1
3 Title 2 1 '1 indicates it is child to row where MyID=1
4 Title 3 1 '1 indicates it is child to row where MyID=1
5 Title 2.1 2 '2 indicates it is child to row where MyID=2
6 Title 2.2 2
7 Title 3.1 3
8 Title 3.2 3
9 Title 4.1 4
10 Title 4.2 4
11 Title 2.1.1 5
13 Title 2.1.2 5
14 Title 2.1.2.1 11
15 Title 2.1.2.2 11
16 Title 2.1.2.1.1 14
17 Title 2.1.2.1.2 14
18 Title 3.1.1 7
19 Title 3.1.2 7
20 Title 3.1.1.1 18
21 Title 3.1.1.2 18
Any anyone show me how to create this tree? I could reach only upto level 2.
Regards,
Vilas
|
|
|
|
|
I dont have the time to make the complete coding but Ill give you my algorithm idea (I will assume that a parent is alyways before its child in the table):
- create an empty HashTable
- loop through all rows
-- create a TreeNode with the name of MyTitle
-- add the TreeNode to the HashTable with MyID as a key
-- if ParentId is 0
--- then
---- add the TreeNode to the top most Nodes collection of your TreeView
--- else
----look into the HashTable with ParentId as the key
---- cast the result to TreeNode
---- add the current TreeNode to the Nodes collection of the found one
-- endif
- loop end
|
|
|
|
|
Hi,
I want to dynamically add nodes to treeview control based on database values.
My database structure in MS-Access is as follows (first row is table columns and then follows the data rows):
MyID MyTitle ParentID
1 Root Title 0 'This is the root
2 Title 1 1 '1 indicates it is child to row where MyID=1
3 Title 2 1 '1 indicates it is child to row where MyID=1
4 Title 3 1 '1 indicates it is child to row where MyID=1
5 Title 2.1 2 '2 indicates it is child to row where MyID=2
6 Title 2.2 2
7 Title 3.1 3
8 Title 3.2 3
9 Title 4.1 4
10 Title 4.2 4
11 Title 2.1.1 5
13 Title 2.1.2 5
14 Title 2.1.2.1 11
15 Title 2.1.2.2 11
16 Title 2.1.2.1.1 14
17 Title 2.1.2.1.2 14
18 Title 3.1.1 7
19 Title 3.1.2 7
20 Title 3.1.1.1 18
21 Title 3.1.1.2 18
Any anyone show me how to create this tree? I could reach only upto level 2.
Regards,
Vilas
|
|
|
|
|
Hi,
Create a datatable (in database) with the colums 'Code' and 'Upcode' Where de upcode for an rootnode = '-' The upcode for de child nodes is the code from the parent node
The you can use following code
Dim TN as new Treenode
Tn.Tag = "-"
Private Sub Groep_Laad(ByVal Nde As TreeNode, ByVal Isroot As Boolean)
Dim GR As New Ole_DB_Groep()
Dim DT As New DataTable()
Dim Teller As Int16
If Isroot Then
GroepTV.Nodes.Clear()
End If
GR.SelectCommand = "SELECT * FROM TableName WHERE upcode ='" & Nde.Tag & "' ORDER BY Code"
GR.Adaptor.Fill(DT)
With DT
If .Rows.Count > 0 Then
For Teller = 0 To .Rows.Count - 1
Dim NewNode As New TreeNode()
NewNode.Tag = "" & .Rows(Teller).Item("Code")
NewNode.Text = "" & .Rows(Teller).Item("Name")
If Isroot Then
GroepTV.Nodes.Add(NewNode)
Else
Nde.Nodes.Add(NewNode)
End If
Groep_Laad(NewNode, False)
Next
End If
End With
DT.Dispose()
GR.Dispose()
End Sub
|
|
|
|
|
I am using a datgrid in my application. I want to highlight a full row, whenever mouse is moved on the row. Any solution.
Thanks
Sumit Domyan
|
|
|
|
|
You have to handle the MouseMove event and call the HitTest function of the DataGrid with the current mouse position. It will return you an object where you can access the Row at the specified position. With the Select function of the grid you can highlight this row (dont forget to unhighlight the previous row with Unselect).
|
|
|
|
|