Creating a Dynamic iCalendar Feed - c#

I am looking for a means to generate a iCalendar feed using .Net , atm I am using the DDay library to generate the iCal file and write it to the response.
The problem with this is if I feed the URL to outlook it says that it is a invalid ics file.
I have tried various routes including :
Using MVC routing so that the link contains a .ics extension.
Changing the Mime Type so that it is Text/Calendar.
One observation I have found is that if I navigate to the URL in a browser a valid iCal file is generated and is imported into Outlook correctly. Secondly if I take that exactly file and host it via IIS as static content , Outlook picks it up as a valid file.
The problem is that I need to generate a Dynamic feed and seem to have run out of things to try and get this working.

It seems the problem in my case was that the default asp.net auth was blocking outlook because it was not authenticating , once a exception was added to the web.config , the URL loaded correctly in outlook

Related

.NET filename with # error - 404 - File or directory not found

I am working on .NET Core 2.2 application (will be upgraded soon). There is a functionality to upload files on the server which can be accessed by other users via a link. Everything works pretty fine. There are checks to prevent files with certain characters including #. The only issue I am having is, client is insisting to allow # in filename. There are no issues when uploading such files, but it doesn't load via link. I get Status Code: 404; Not Found error. This was the issue in legacy site (ASP.NET WebForms) as well where it was showing 404 - File or directory not found..
The URL I get looks like this: /_ClientData/NTTF/Announcements/61/Docs/invalid%20#%20test.pdf
As a last option, I can allow this files and replace # with something else on server, but I am wondering if there is any way to make this work without manipulating filename.
You probably have an Razor page (or equivalent) that dynamically generates the "clickable link".
SUGGESTION: Use HttpUtility.UrlEncode() to explicitly generate the link, as you serve the page.
It should generate something like this:
File Name: invalid # test.pdf
HttpUtility.UrlEncode: invalid%20%23%20test.pdf

PDF does not reload on directory browsing

Hi guys this is my follow up question and I think this is the real issue here. Click Here
Whenever I access the file using the directory browsing (eg. http://localhost/temp/1.pdf) it always render the old or previous PDF file even if I change the entire file with the same file name, example I have 1.pdf with some content then I delete this file on the directory then replace with new and different content and rename it to 1.pdf then when I access it using browser it always render the previous value not the new one that I replace. This only happens on IE and Opera browser. Please need help this is a production issue.
Edit:
I found something very strange, example i have this url for the location of the pdf file (eg. http://localhost/website/tempfolder/1.pdf) the first pdf that I generated will show then some part in my code I change the casing of some letter example 't', I change it to 'T' then the newly pdf shows but when I revert back to the old case expecting that it will show the new pdf but sad to say the first PDF file shows.
Your browser is probably caching the PDF files.
For IE, you can do a CTRL F5 to force it to reload from web server.
Or put a random query string in your URL
e.g. /temp/1.pdf?v=1, /temp/1.pdf?v=2
Assuming you server is IIS, permanent solution is to configure HTTP response headers.
Go to IIS manager
Navigate to your folder
Click "HTTP Response Headers" in Features View
Right-button click/select "Set Common Headers"
Check "Expire Web Content" and select "Immediately".

PDF binary data output in .NET

I have a question about outputting PDF files. Currently I'm storing the PDF in the database in binary form. I'm outputting the PDF file via a URL such as:
http://myhost.com/FileManager.aspx?FileId=8465b2f9-b64e-4a9a-a449-94b5adb3b278
so from what I could deduce, to the browser this is an .aspx page that is loading and not a PDF. Firefox and IE interpret this correctly and launch Adobe Acrobat, however since Chrome (12.0.742.112) has its own implementation of a PDF reader, it will open the file correctly, but then when someone goes to save the file in chrome, it wants to save it as a .aspx. If I simply rename the .aspx to .pdf, the file downloads correctly. However, I"m trying to avoid telling my customer that s/he may have to take that extra step.
When I chose to look at the headers that loaded in Chrome via Web Inspector, I see this:
FileManager.aspx:-1 Resource interpreted as Document but transferred
with MIME type application/pdf
I can completely understand why Chrome would say this.
Furthermore, I get a save as box upon page load when I add:
Response.AddHeader("content-disposition", "attachment;filename=blah.pdf");
However, I was hoping to just keep the file in a browser. So aside from using some URL Rewrite, is there a way I can manipulate the HTTP Headers to simply open the page as a PDF and save correctly in Chrome?
Lastly, I tried using a WebService, but I can't seem to write the binary data to the page.
this.Context.Response.BinaryWrite(bytes);
Any help is appreciated!
In the web application's top-level web.config, add the following <add> element to the <httpHandlers> section:
<httpHandlers>
<add verb="*" path="FileManager.pdf" type="ProjectName.FileManager" />
...where ProjectName.FileManager is the full name (namespace and classname) of the FileManager class in FileManager.aspx.cs.
This tells ASP.NET to handle the path /FileManager.pdf using the handler defined by ProjectName.FileManager. (System.Web.UI.Page implements the IHttpHandler interface, so every webform is a handler.)
Now you can serve the PDFs via a URL with a .pdf extension like so:
http://myhost.com/FileManager.pdf?FileId=8465b2f9-b64e-4a9a-a449-94b5adb3b278
You do not need to rename the physical FileManager.aspx file. When the user enters /FileManager.pdf?FileId=foo in the browser, ASP.NET will handle the request with the ProjectName.FileManager class defined in FileManager.aspx.
Note:
The above should work on Cassini (the Visual Studio "mini" webserver) with no further changes. However IIS by default only sends *.aspx, *.asmx, *.ashx requests to ASP.NET. Therefore, for the above to work on IIS, you need to tell it to send requests for /FileManager.pdf to ASP.NET. That is, you need to configure a "mapping".
With IIS 6 you need to configure the mapping using IIS manager.
With IIS 7 you can configure a mapping from your web.config--this makes deployment easier, but it depends on how your hosting is set up.
Something that worked for me was to add the intended filename between the application page name (in your case, FileManager.aspx) and the query mark (the ? mark).
So, in the end, you'd have something like this:
http://myhost.com/FileManager.aspx/myfile.pdf?FileId=8465b2f9-b64e-4a9a-a449-94b5adb3b278
Surprisingly, the correct application will run (Filemanager.aspx), the variables will be passed unharmed (FileId), the result will be treated as inline (if you didn't change it to attachment, that is) but the browser will think that the filename to use, in case the user wants to save the page, is myfile.pdf.

Dynamic PDFs and Android default browser

I am working on delivering PDF files that are generated on demand to users of mobile devices. I am using ASP.NET MVC 2 and I generate the PDF using the Report Viewer local report export as PDF.
This gives me the raw byte[] of PDF content.
I then return it using:
return File( pdf , mimeType , "FileName.pdf" );
Note, I have tried it with and without the "FileName.pdf" default name for saving the file.
It works great in desktop browsers and iPhones. I have tested with the WP 7 emulator and it seems like it would work if it could just read PDFs (it prompts for the proper file name to save it).
Android seems to be complaining, however.
I have tested on Droid-X and Droid devices and it always shows " Download unsuccessful" in the browser download results. On Opera Mini it prompted to save the file (when using the return method that included the file name) and the PDF opened fine after it was saved on the device.
I can return PDF files that already exist on disk just fine with: File( "~/filename.pdf" , "application/pdf" ); so it seems to just be a problem with dynamic PDFs.
Has anyone dealt with this issue before?
I have tested on Droid-X and Droid devices and it always shows " Download unsuccessful" in the browser download results.
AFAIK, that means either that the HTTP request failed or that the MIME type was not one for which there is an ACTION_VIEW activity registered. Bear in mind that the DROID did not ship with a PDF viewer, and I forget if the DROID X did or not.
I agree with Chris, in that it feels like the problem is an invalid MIME type. Consider using curl or a browser plugin to inspect your HTTP response headers and confirm that, indeed, application/pdf is being returned as the MIME type.
If that does not help, and you can supply us with a URL to test, that would help as well.
I see this questions id from years ago, but if you just want to display the pdf, you can embed your pdf URL in google doc viewer, and then reference that URL, then it should open on android browsers.
However, this will only work if your URL is publicly accessible.

How to identify whether the client machine supports PDF File format

Hii,
My requirment is to show a dynamically created pdf file directly to my web page. It works fine for the system which is having pdf reader software. But for the system which does not have the pdf software it is showing error like below
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
An invalid character was found in text content. Error processing resource 'http://localhost:4252/OmanePost/Customer/EBox/PD...
I need to handle this situation bit differently.i.e In this situation the file should be save to the physical location of the system for that i need to identify whether the client machine has pdf software or not then i can manage properly
I m using ASP.NET 2.0 version
It looks to me that you are serving your PDF with an XML mime/content-type. Make sure you set your content-type to application/pdf and you'll probably get a more suitable browser response.
In this case the browser should ask the user to open the file in an external application.
Please verify that you are sending the correct Content-Type: application/pdf header. Certain versions of Microsoft's browser ignore the content-type header, so you need to specify a filename ending in .pdf in the content disposition header: Content-Disposition: inline; filename=filename.pdf;
Note: I have not verified that it works with "inline" instead of "attachment", but I think it is worth a try.
My requirment is to show a dynamically created pdf file directly to my web page.
Try online ZohoViewer that takes a PDF file link and displays in the browser without requiring PDF reader on the client machine. As such there's no way to check if the client machine has a pdf reader or not.
You can not identify that client system has pdf software using javascript, asp.net, c#.
If the PDF reader software is not there and the PDF is a valid PDF then it should not throw exception. Instead it asks for a software in client machine which can read the file.

Categories