c# - Attempted to read or write protected memory. This is often an indication that other memory is corrupt -
i'm working on windows form project , creates pdf file. want save file user want to. use savefiledialog this. when click "save pdf" button on form error code.
attempted read or write protected memory. indication other memory corrupt.
if don't use savefiledialog (if give static name file), don't error.
here button click code:
private void button2_click(object sender, eventargs e) { savefiledialog savefiledialog1 = new savefiledialog(); savefiledialog1.initialdirectory = convert.tostring(environment.specialfolder.mydocuments); savefiledialog1.filter = "(*.pdf)|*.pdf|all files (*.*)|*.*"; savefiledialog1.filterindex = 1; savefiledialog1.showdialog(); if (savefiledialog1.filename != "") { itextsharp.text.document pdfdosya = new itextsharp.text.document(pagesize.a4, 20, 20, 10, 10); pdfwriter.getinstance(pdfdosya, new filestream(savefiledialog1.filename, filemode.create));//todo dosya ismi pdfdosya.open(); } }
how can solve problem.
this problem:
you can't use convert.tostring(environment.specialfolder.mydocuments)
folder path string, it's enum. need use environment.getfolderpath(environment.specialfolder.mydocuments)
path string enum value.
Comments
Post a Comment