TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Andrew
NA
11
0
Very strange export to csv behaviour!
Jul 27 2011 5:21 AM
Hi All, i have two button on two different tab pages of a tab control. Each one calls the same sub to generate a csv file by providing a filename, the datagridview, a boolean to display columnheaders, and the delimiter value.
As you can see there is no difference between the two calls other than the filename and datagridview reference. So why is it btnExportEnquiry works fine but btnExportVolumes give the error: "Access to the path 'C:\exporttest2.csv' is denied." ?????????????
This happens regardless of what order i click them and whether or not the file already exists. btnExportEnquiry always works, btnExportVolumes always fails.
ExportDGVToCSV(
Private
Sub
btnExportEnquiry_Click(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
btnExportEnquiry.Click
"C:\exporttest.csv"
, grdEnquiry,
True
,
","
)
End
Sub
ExportDGVToCSV(
Private
Sub
btnExportVolumes_Click(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
btnExportVolumes.Click
"C:\exporttest2.csv"
, grdDocType,
True
,
","
)
End
Sub
Private
Sub
ExportDGVToCSV(
ByVal
strExportFileName
As
String
, _
ByVal
DataGridView
As
DataGridView, _
Optional
ByVal
blnWriteColumnHeaderNames
As
Boolean
=
True
, _
Optional
ByVal
strDelimiterType
As
String
=
","
)
Dim
sr
As
IO.StreamWriter = File.CreateText(strExportFileName)
Dim
strDelimiter
As
String
= strDelimiterType
Dim
intColumnCount
As
Integer
= DataGridView.Columns.Count - 1
Dim
strRowData
As
String
=
""
If
blnWriteColumnHeaderNames
Then
strRowData += Replace(DataGridView.Columns(intX).Name, strDelimiter,
IIf(intX < intColumnCount, strDelimiter,
sr.WriteLine(strRowData)
For
intX
As
Integer
= 0
To
intColumnCount
""
) & _
""
)
Next
intX
End
If
strRowData =
For
intX
As
Integer
= 0
To
DataGridView.Rows.Count - 1
""
strRowData += Replace(DataGridView.Rows(intX).Cells(intRowData).Value, strDelimiter,
IIf(intRowData < intColumnCount, strDelimiter,
sr.WriteLine(strRowData)
sr.Close()
sr.Dispose()
MsgBox(
For
intRowData
As
Integer
= 0
To
intColumnCount
""
) & _
""
)
Next
intRowData
Next
intX
"Done!"
)
End
Sub
Reply
Answers (
5
)
How to convert webcam captured picture to byte
Pass login credentials to flickr webpage