Free Support Forum - groupdocs.com

URL Length No More than 260 Characters


#1

When trying to set an external URL to a file in the Viewer I’m getting an Arg exception in .NET saying the name can be no longer than 260 characters.


As an example:

.Url(“http://rack.3.mshcdn.com/media/ZgkyMDE0LzAxLzMwLzE2L0dydW1weUNhdENvLmQ3NGM4LmpwZwpwCXRodW1iCTEyMDB4OTYwMD4/df6447b7/dd8/Grumpy-Cat-Colonel-Meow.jpg”)
.Url(“http://kittentoob.com/wp-content/uploads/sites/4/2013/08/1016colonel_meow.jpg”)
.ZoomToFitWidth(true)

The first URL would fail, the second works.

How should we handle longer URLs?

Thank you,

Mike

@(Html.ViewerClientCode()
.TargetElementSelector("#test")
.Url(“http://rack.3.mshcdn.com/media/ZgkyMDE0LzAxLzMwLzE2L0dydW1weUNhdENvLmQ3NGM4LmpwZwpwCXRodW1iCTEyMDB4OTYwMD4/df6447b7/dd8/Grumpy-Cat-Colonel-Meow.jpg”)
.ZoomToFitWidth(true)
.Width(1200)
.Height(900)
.DownloadPdfFileIfPossible()
.PreloadPagesCount(1)
.UseHtmlBasedEngine())

#2

Hello Mike,

We are sorry to hear that you have such issue. Unfortunately 260-char limit is an internal and inherent property of WinAPI and MS Windows at all, so the problem that you had described is not a bug but rather an inherited limitation (Why does the 260 character path length limit exist in Windows?). But we have good news for you - you can overpass this as described below.

You need to obtain a target document as a stream and pass this stream to the GroupDocs.Viewer. Please see an example:

Instead of
.Url(“http://rack.3.mshcdn.com/media/ZgkyMDE0LzAxLzMwLzE2L0dydW1weUNhdENvLmQ3NGM4LmpwZwpwCXRodW1iCTEyMDB4OTYwMD4/df6447b7/dd8/Grumpy-Cat-Colonel-Meow.jpg”)

use
.Stream(HttpWebRequest.Create
(“http://rack.3.mshcdn.com/media/ZgkyMDE0LzAxLzMwLzE2L0dydW1weUNhdENvLmQ3NGM4LmpwZwpwCXRodW1iCTEyMDB4OTYwMD4/df6447b7/dd8/Grumpy-Cat-Colonel-Meow.jpg”)
.GetResponse().GetResponseStream(), “Grumpy-Cat-Colonel-Meow”, “jpg”, “Grumpy-Cat-Colonel-Meow.jpg”)

Please note that you need to specify a file name and extension in order to allow GroupDocs.Viewer to save this file in the “temp” subfolder properly.

If you will have more questions please feel free to contact us.