I am getting an error while exporting data to an excel sheet.
Code
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=CompletionDatesReport.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
gridData.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
Error
Internet explorer cannot download abc.aspx from www.xyz.com.
Internet explorer was not able to open this internet site.The requested site is either unavailable or cannot be found.Please try again later.
Remove the line no 4
Response.Cache.SetCacheability(HttpCacheability.NoCache)
It will be work.
Related
Trying to create an invite only wiki, that we can login to with a bot account once the customer has authenticated using our own webpage on our corporate website.
I've been using the documentation from here:
https://www.mediawiki.org/wiki/API:Login
Anyway I can get a success response from the API sandbox, but the POST from our new API interface webpage errors with "Unable to continue login. Your session most likely timed out."
I get the same message even if I deliberately enter invalid login credentials, so I would imagine it's not getting as far as actually checking the username/password/token. It's really annoying that there's no decent error to work from.
GETting a token via action=query works fine from the same webpage.
Our webpage is a web forms page written in VB (I know).
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
ServicePointManager.DefaultConnectionLimit = 9999
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("https://tmsinsight.com/TMSWiki/api.php?action=query&meta=tokens&type=login&format=json")
Dim j As Object = New JavaScriptSerializer().Deserialize(Of Object)(result)
Dim LoginToken As String = j("query")("tokens")("logintoken")
Response.Write(LoginToken & "<br/>")
webClient.Headers(HttpRequestHeader.ContentType) = "application/x-www-form-urlencoded"
Dim parameters = New NameValueCollection()
parameters.Add("action", "login")
parameters.Add("format", "json")
parameters.Add("lgname", "botusername#botusername")
parameters.Add("lgpassword", "botpassword")
parameters.Add("lgtoken", LoginToken)
Dim responsebytes = webClient.UploadValues("https://tmsinsight.com/TMSWiki/api.php", "POST", parameters)
Dim resultRequest = Encoding.UTF8.GetString(responsebytes)
Response.Write(resultRequest)
My web page has a link
href="https://...myapi.../files/get-user-role-file?fileID=etc..." target="_blank"
The web api call (get-user-role-file) returns a file with a mime type and a content disposition of inline.
the code returns a HttpResponseMessage. here is some of the code
ByteArrayContent content = new ByteArrayContent(_bytes);
string dispositionType = "inline";
if (_mimetype.IndexOf("octet-stream") > 0) dispositionType = "attachment";
ContentDispositionHeaderValue contentDisposition = new ContentDispositionHeaderValue(dispositionType) {
FileName = _filename
};
MediaTypeHeaderValue contentType = new MediaTypeHeaderValue(_mimetype);
response.Content = content;
response.Content.Headers.ContentDisposition = contentDisposition;
response.Content.Headers.ContentLength = _bytes.Length;
response.Content.Headers.ContentType = contentType;
This works in chrome and safari and firefox. In Edge it works for me in VS debug or in InPrivate mode or when run locally from my machine in IIS. It also works if the file type is one that can be opened in the browser OR if I have Fiddler running. BUT it does not work, for example, with a Excel doc in Edge run normally off of the web server. It does work for everyone else I have asked so far.
I have tried updating Edge and clearing all history.
What happens is a new tab is opened with the file URL and the downloads modal opens with a file named get-user-role-file.json and a message says "Couldn't download - Something went wrong...". In the network tab of the dev tools the call returns OK 200 and no error but also no response (Failed to load response data: No resource with given identifier found).
It's a mystery.
I'm trying to create a copy of a mailItem in my sent folder. Once I create it, I save the msg in the folder. It works for all mailItems , except when I try to save a mailItem with an attachment where I disallow the save attachment permission in outlook. Why does the mailItem.Save() not saving the mailItem only for this scenario?
In the code below, I'm using redemptions to create a copy in sent folder. msg.save() saves all mails but the one I mentioned above. Also I tried saving the mailItem before the creation, but it does not generate entryId.
static void CreateSentFolderMail(Redemption.SafeMailItem newSentMail, string nvdID, Outlook.MailItem mailItem, Redemption.SafeMailItem safeMailItem)
{
RDOFolder folder = Globals.ThisAddIn.session.GetDefaultFolder(rdoDefaultFolders.olFolderSentMail);
RDOMail msg = (RDOMail)folder.Items.Add(newSentMail);
RDOMail originalmsg = Globals.ThisAddIn.session.GetMessageFromID(mailItem.EntryID);
msg.Sent = true;
msg.SentOn = DateTime.Now;
msg.ReceivedTime =msg.CreationTime;
msg.Subject = safeMailItem.Item.Subject;
msg.To = safeMailItem.Item.To;
msg.BCC = safeMailItem.Item.BCC;
msg.Body = safeMailItem.Item.Body;
msg.Recipients = originalmsg.Recipients;
msg.Sender = Globals.ThisAddIn.session.CurrentUser;
msg.SentOnBehalfOf = Globals.ThisAddIn.session.CurrentUser;
msg.SetProps(NVDMailHeaderUtils.PS_INTERNET_HEADERS + NVDMailHeaderUtils.NVD_HEADER_ID, nvdID);
msg.Save();
}
I had used session.GetRDOObjectFromOutlookObject before calling this method to get a RDOAttachment object. But after using this: session.GetRDOObjectFromOutlookObject I was not able to the save the mailitem. Save was not getting executed and hence the EntryId was not getting generated. Due to this issue I was getting an error here : RDOMail originalmsg = Globals.ThisAddIn.session.GetMessageFromID(mailItem.EntryID); saying "invalid entry Id". I installed the new version of redemptions that solved this problem.
I'm using EPPlus to generate excel (.xlsx) in my mvc3 web application. It works fine with my localhost. However, after i deployed to the server, the excel file return as an Excel Binary Workbook. Can anyone help me?
Here is how i generate my excel (.xlsx):
ExcelPackage pck = new ExcelPackage();
ExcelWorksheet ew = pck.Workbook.Worksheets.Add("template" + templateVM.Year);
List<YieldsTemplate> list = mgr.GetTemplates(templateVM.Year);
ew.Cells["A1"].LoadFromCollection(list, true);
ew.Cells["A:AZ"].AutoFitColumns();
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment: filename=" + "abc" + ".xlsx");
Response.BinaryWrite(pck.GetAsByteArray());
Response.End();
thank you!!
I have a scenario where I need to get signature information from a pdf with the iText7 library. The signature may or may not exist. When I instantiate a new SignatureUtil object for a PDF that does not have any digital signatures I get the exception
"There is no associate PdfWriter for making indirects."
. If an signature is there it works fine. I'm not sure how to correct this exception.
UPDATED to include code sample
Using reader As New PdfReader(pdfPath),
pdf As New PdfDocument(reader)
Dim util As New SignatureUtil(pdf)
Dim signModel As String = "[Signature: {0} - {1}]"
For Each signame As String In util.GetSignatureNames()
Dim whoisthis As PdfSignature = util.GetSignature(signame)
returnVal &= String.Format(
signModel,
whoisthis.GetName(),
whoisthis.GetReason
)
Next
End Using
The exception is thrown because there is no AcroForm in the document and SignatureUtil tries to add it, but there is no associated PdfWriter.
As a workaround you can check if a document contains an AcroForm:
PdfAcroForm.getAcroForm(document, false) != null
And only create SignatureUtil if there is an AcroForm. If there is no AcroForm there will be no signature fields.