Use of (“Content-Disposition”, “inline; filename=” + fileName +"") not showing the file name - content-disposition

file name: abc.aspx
my code:
string Path = #"E:\documents\Data20160129110355.xls";
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename=Data20160129110355.xls");
HttpContext.Current.Response.TransmitFile(Path);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
On click of "Open" it will open the file successfully but the header of the file are not showing "Data20160129110355.xls". It's showing abc.aspx.
How to solve this problem please reply.

Hope this will help:
Content-Disposition:What are the differences between "inline" and "attachment"?
replace 'inline' with 'attachment'.
UP: try this:
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=Data20160129110355.xls");

Related

JIRA cloud scriptrunner - Bad filename after post attachment

I have a problem with a filename when I try to post attachment into an issue. If the attachment's filename contains non ASCII characters, the characters are changed into the question marks, eg. "?esk?_Republika.png" vs. "Česká_Republika.png". The attachment is always saved into an issue and I can properly open it, the file is OK.
The code is:
def fileName = 'Česká_Republika.png'
def attachmentContent = get('/rest/api/3/attachment/content/10078')
.header('Accept', 'application/json')
.asBinary()
.body
InputStream stream = new ByteArrayInputStream(attachmentContent.getBytes())
def attachmentPost = post('/rest/api/3/issue/TIP-63/attachments')
.header('Accept', 'application/json')
.header('X-Atlassian-Token', 'no-check')
.field('file', stream, fileName)
.asJson()
I hope for your kind help and look forward for your answers.
Thank you in advance so much.
Lukas

Karate: Multipart file : read works but passing content in value fails

I have a endpoint with a multipart request which takes two files as part of the request parameter.
I tried with the below snippet with read and it worked, but my use case is to take content from a file and pass it to the value parameter.
Can I pass the content as a file?
The working code if my I try to read the file from directory is
Working feature::
Scenario:
* configure headers = {'Content-Type' : 'multipart/form-data', 'Authorization': 'Bearer sgahshshshs'}
Given url "http://filecompare.com/compare"
And multipart file oldfile = { read: './oldfile.json', filename: 'oldfile.json'}
And multipart file newfile = { read: './newfile.json', filename: newfile.json'}
When method post
Then status 200
Not working feature::
Scenario:
Given url "http://download-oldfile/oldfile"
When method get
* def oldfile = response
Given url "http://download-newfile/newfile"
When method get
* def newfile = response
* configure headers = {'Content-Type' : 'multipart/form-data', 'Authorization': 'Bearer sgahshshshs'}
Given url "http://filecompare.com/compare"
And multipart file oldfile = { value: '#(oldfile)', filename: 'oldfile.json'}
And multipart file newfile = { value: '#(newfile)', filename: newfile.json'}
When method post
Then status 200
The contents are printed correctly but api returns error when I use value
Please let me know if I am missing something as part of running with the value keyword in multipart file.
Thank you
Can't think of anything other than try to convert the value to a string:
* string oldfile = response
If still stuck, follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
Had the same issue, resolved without needing to save to file by defining a variable holding the JSON object and using set to manipulate its value.
In your case this would look like:
* def temp = {value: '', filename: 'oldfile.json'}
* set temp.value = oldFile
#[...]
And multipart file oldFile = temp

Alfresco : How to search for a specific files types?

I am working to search all PNG files(i.e. all files which has file name extension ".png") in alfresco.
I am using the followingcode, but it does not return any result:
var docs = search.luceneSearch("#cm\\:content.fileType:\"*.png\"");
for (var i=0; i<docs.length; i++)
{
//TO print the name of files--> "Name: " + docs[i].name ;
}
I am not sure if content.fileType is the right way to code to search for file types. Any suggestion please ?
You should go with the content.mimetype query, for example: #\{http\://www.alfresco.org/model/content/1.0\}content.mimetype:text/plain
https://community.alfresco.com/docs/DOC-4673-search#jive_content_id_Finding_nodes_by_content_mimetype
If I use this statement, it helps to find only PNG images:
var docs = search.luceneSearch("#cm\\:name:\"png\"");
If your really want to search for PNG files you should follow Lista's approach using mimetype but with correct syntax
var docs = search.luceneSearch("#cm\\:content.mimetype:\"image/png\"");
searching for name part "PNG" ("#cm\:name:\"png\"") would find any document having a token "PNG" in it's name like png.name.pdf or any_png.doc since document name is stored tokenized in the index

Get only file name from openfiledialog [duplicate]

I am using the following method to browse for a file:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.FileName
Is there a way get ONLY the file name?
The FileName method returns the entire path and file name.
i.e. I want Foo.txt instead of C:\SomeDirectory\Foo.txt
Use Path.GetFileName(fullPath) to get just the filename part, like this:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
C++ code for obtain filename and complete path in OpenFileDialog:
textBox1->Text = OpenFileDialog1->FileName; //complete path
textBox1->Text = System::IO::Path::GetFileName(OpenFileDialog1->FileName); //filename
Suppose that I did select word2010 file named as "MyFileName.docx"
This is for ONLY the selected file extension "including the dot mark, f.e (.docx)"
MsgBox(System.IO.Path.GetExtension(Opendlg.FileName))
And this for the selected File name without extension: (MyFileName)
MsgBox(System.IO.Path.GetFileNameWithoutExtension(Opendlg.FileName))
and you can try the other options for the "PATH Class" like: GetFullPath,GetDirectoryName ...and so on.
if you want just the selected name without Extension you can try this code
Imports System.IO
PictureNameTextEdit.Text = Path.GetFileNameWithoutExtension(OpenFileDialog1.Fi‌​leName)
thanx
//Following code return file name only
string[] FileFullPath;
string FileName;
objOpenFileDialog.Title = "Select Center Logo";
objOpenFileDialog.ShowDialog();
FileFullPath = objOpenFileDialog.FileNames[0].ToString().Split('\\');
FileName = FileFullPath[FileFullPath.Length - 1]; //return only File Name
//Use following code if u want save other folder ,
// following code save file to CenterLogo folder which inside bin folder//
System.IO.File.Copy(OFD.FileName, Application.StartupPath +
"/CenterLogo/" + FileName, true);
Use SafeFileName instead of FileName and it will return a name (and extension) without path.
Use this code to put the filename in PictureNameTextEdit:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.SafeFileName

Return FileName Only when using OpenFileDialog

I am using the following method to browse for a file:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.FileName
Is there a way get ONLY the file name?
The FileName method returns the entire path and file name.
i.e. I want Foo.txt instead of C:\SomeDirectory\Foo.txt
Use Path.GetFileName(fullPath) to get just the filename part, like this:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = System.IO.Path.GetFileName(OpenFileDialog.FileName)
C++ code for obtain filename and complete path in OpenFileDialog:
textBox1->Text = OpenFileDialog1->FileName; //complete path
textBox1->Text = System::IO::Path::GetFileName(OpenFileDialog1->FileName); //filename
Suppose that I did select word2010 file named as "MyFileName.docx"
This is for ONLY the selected file extension "including the dot mark, f.e (.docx)"
MsgBox(System.IO.Path.GetExtension(Opendlg.FileName))
And this for the selected File name without extension: (MyFileName)
MsgBox(System.IO.Path.GetFileNameWithoutExtension(Opendlg.FileName))
and you can try the other options for the "PATH Class" like: GetFullPath,GetDirectoryName ...and so on.
if you want just the selected name without Extension you can try this code
Imports System.IO
PictureNameTextEdit.Text = Path.GetFileNameWithoutExtension(OpenFileDialog1.Fi‌​leName)
thanx
//Following code return file name only
string[] FileFullPath;
string FileName;
objOpenFileDialog.Title = "Select Center Logo";
objOpenFileDialog.ShowDialog();
FileFullPath = objOpenFileDialog.FileNames[0].ToString().Split('\\');
FileName = FileFullPath[FileFullPath.Length - 1]; //return only File Name
//Use following code if u want save other folder ,
// following code save file to CenterLogo folder which inside bin folder//
System.IO.File.Copy(OFD.FileName, Application.StartupPath +
"/CenterLogo/" + FileName, true);
Use SafeFileName instead of FileName and it will return a name (and extension) without path.
Use this code to put the filename in PictureNameTextEdit:
OpenFileDialog.ShowDialog()
PictureNameTextEdit.Text = OpenFileDialog.SafeFileName