Sharepoint 2010 -Script to get file name from Document Library
Hi
can anybody send be script that works in "SharePoint 2010 management Shell" to get list of file names in document library.
Thank
See my updated answer. The double quotes need to be removed. Also note that you need to use $item.File.Name
and not $item.Name to get the name of the files.
Blog | SharePoint Learnings CodePlex Tools |
Export Version History To Excel |
Autocomplete Lookup Field
Similar Messages
-
Get File name from incoming IDoc
HI All,
I am in an IDOC to File scenario using Fcc. (R/3 --> XI --> 3rd party)
I need to use the idoc-number(EDI_DC40-Docnum) as my output file name. I planned using variable substitution but there it expects me to get the idoc number from payload which I do not have it in. (refer c ode below)
As I understand, variable substitution can be used only on payload(the FINAL data set that we will be writing to the file).
Can we use the data which is part of incoming IDOC and not part of payload(final data what we are writing to file).??
Other idea was to map this IDOC no to a field in final file, but this field should not be written in the output file, so am confused about how to achieve this.
E.g
*Incoming Data*
IDOC
|_EDI_DC40
|_DOCNUM
Final data (Payload)
Header
Data
Trailer
As seen in my example above I do not have the IDOC no in the final data so how do I use the Idoc no as my filename? Apprecaite your help on same.
Regards
ShirinHi
You can use dynamic configuration to get the file name .
Use Adapter Specific Message Attributes for the target Comm Chanel check the indicator for filename in the advanced tab of CC
create a UDF with i/p as file name i.e the Idocnum field and
paste this code
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//conf.removeAll();
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
//String filename= conf.get(key);
conf.put(key, fileName);
key= null;
return fileName;
PS: use cache as value in UDF
ands assign the o/p of this UDF to a root node -
Hi all,
how to find a .txt file in a particular folder. My text file comes with
following name <fixed_name>.<mmddyy><hhmmss>, e.g., fn_fnprod.102806015605
so how to get this file name. nd also tell me if there are multiple files
then how to retrieve the oldest one first and so on....
Thanks & Regards
Gauravit's fine but how to know which is older file b'cpz
this file comes every day with new date & time. so
what if there a multiple file. nd i have proceed
oldest first.
pls help asapget each file last modifed, using file.lastModified() method and compare which file you would be needing. =) -
How to get file name from file adapter (Read Operation)
Hi All,
I am reading files from local location, in jca file i gave filename property =*.* ( which reads all files), and now I want to read the incoming file name inside bpel and I want to copy the file name to some variable. Is this possible?Yes, its possible.
In your receive activity,set below property in its properties tab:
<bpelx:property name="jca.file.FileName" variable="FileName"/>
Before that make sure to create a variable "FileName" of string type.
Whatever file your file adapter will read,its name will be stored in this variable.
Hope this helps.
Regards,
Karan
http://learn-oraclesoa.blogspot.com/ -
Need help getting files names from directory
I have never done anything in php before and I'm struggling.
In an attempt to search through potential document names in a directory, I've added the following code to a new php document:
<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
closedir($handle);
?>
with no luck. When executed all I get is a blank screen. Any ideas why?
End goal is to list the file names in the directory so that the user can choose to open desired document. Thanks!Click here and pick the option which best fits your situation.
(93771) -
Set unique file name for document library in SharePoint 2013
Hi,
I have document library in the sharepoint 2013 with two dropdown fields-dept name,dept id.
My requirement is to create a namiing convention for each file uploded in the document library.
So the naming convention should be "deptname-deptid-filename-Id".
I tried this naming convention using workflow as below-
In this case ,first I attach the file and then it asks for dept name & id,Whwn i input these value,it shows error message as this file is modified by you at this point of time.On cancel it saves the attached file but does not save the deptname and dept
id.
please help if any idea or suggestion.
Thank you.The only way I've ever seen this work while adding a new file is to use an Event Reciever. Build an Event
Receiver that fires whenever a file is added and have the code change the name of the file from whatever the user titled it to the naming convention you are using.
Paul Stork SharePoint Server MVP
Principal Architect: Blue Chip Consulting Group
Blog: http://dontpapanic.com/blog
Twitter: Follow @pstork
Please remember to mark your question as "answered" if this solves your problem. -
C#/REST Getting files in a document library using Internal Name
Hi Folks,
I need to get a list of files in a SP2010 and SP2013 document library using the REST API - this is occurring inside a timer service application so am using C#. As a constraint I need to use the internal names for the document libraries - primarily
because users tend to change the display name and this is an automated service.
When I make a call to _api/web/GetFolderByServerRealitveUrl('/Shared Documents')/Files I get a bunch of XML but how do I get just a list of filename+ext. I am using Xdocument (LINQ to XML). I need to retrieve the name property in the
contents sub element for all files returned.
Second question, how to I change this to use the internal name '/Document' instead of '/Shared Document', so that it copes with users changing the display name of document libraries.
Regards
AndyHi Andy,
1.For your issue, you can refer to the code as below:
using System.Xml;
namespace REST_XML_LIST_GET
class Program
static XmlNamespaceManager xmlnspm = new XmlNamespaceManager(new NameTable());
static Uri sharepointUrl = new Uri("Site URL/");
static void Main(string[] args)
xmlnspm.AddNamespace("atom", "http://www.w3.org/2005/Atom");
xmlnspm.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
xmlnspm.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
NetworkCredential cred = new System.Net.NetworkCredential("username", password", "domain");
HttpWebRequest listRequest = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "_api/Web/lists/getByTitle('List Name')/items");
listRequest.Method = "GET";
listRequest.Accept = "application/atom+xml";
listRequest.ContentType = "application/atom+xml;type=entry";
listRequest.Credentials = cred;
HttpWebResponse listResponse = (HttpWebResponse)listRequest.GetResponse();
StreamReader listReader = new StreamReader(listResponse.GetResponseStream());
var listXml = new XmlDocument();
listXml.LoadXml(listReader.ReadToEnd());
//Method 1 Seperate node list
var titleList = listXml.SelectNodes("//atom:entry/atom:content/m:properties/d:Title", xmlnspm);
var idList = listXml.SelectNodes("//atom:entry/atom:content/m:properties/d:ID", xmlnspm);
int i = 0;
foreach (XmlNode title in titleList)
Console.WriteLine(title.InnerXml+" "+idList[i++].InnerXml);
//Method 2 single node list
var prop = listXml.SelectNodes("//atom:entry/atom:content/m:properties", xmlnspm);
foreach (XmlNode ndlist in prop)
Console.WriteLine(ndlist.SelectSingleNode("d:Title", xmlnspm).InnerXml + " " + ndlist.SelectSingleNode("d:ID", xmlnspm).InnerXml);
Console.ReadLine();
2. For a workaround, you can get the display name based on the internal name and use the display name in the Rest API.
Reference:
http://www.c-sharpcorner.com/UploadFile/Roji.Joy/working-with-sharepoint-2013-rest-api-in-a-C-Sharp-managed-code/
https://dlr2008.wordpress.com/2013/11/14/sharepoint-2013-rest-api-the-c-connection-part-4-document-libraries-folders-and-files/
Thanks,
Eric
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected].
Eric Tao
TechNet Community Support -
How to get File object from Document Object . ?
In conventional Dom Parsing we pass file to DocumentBuilder to get Document Object .
File file = new File("c:\\MyXMLFile.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file); // gOT Document here . My problem is how do i get File object back from Document . If i have Document object with mi.
Please consider above code as example i dont have File object in my code . i am using Xhive DB API where i get Document directly from API method .
I need to convert this Document to File to get size of file
Please suggest solution on this
Edited by: AmitChalwade123456 on Dec 5, 2008 6:10 AMHello Guys any views on this topic
-
SharePoint 2010 Cache Not working for Publishing Images Document Library
Hi
I am using SharePoint 2010 Publishing Site and have enabled anonymous access.
I have enabled blob cache and object cache in the site.
While i was checking with fiddler those objects in style library and other document libraries are cached.
Whereas the images from the document library Publishing images is not cached; its returning 304 Not Modified status code.
Is there a way to include the Publishing images to be cacheable as well ?
Please advise
Ready for ActionDid you perform IISreset on all sharepoint server after enabling cache
http://technet.microsoft.com/en-us/library/cc261797%28v=office.15%29.aspx
To use the page output cache and the associated cache profile settings, you must be using the Publishing feature on your site.
http://sharepointinterface.com/tag/caching/
Wiley went out to SharePoint, checked the article that he wrote, and saw that he did indeed use a series of dynamite sticks for an image. The page should have actually appeared as it does in the screenshot that is above and to the left. After a quick facepalm,
Wiley realized that he needed to make a change – and fast.
Wiley went out to the Publishing Images library for the site collection and uploaded a new version of the
newsarticleimage.jpg image file – one that contained a barrel of TNT instead of a bundle of dynamite. He then browsed to the article page and did a refresh.
Nothing changed.
Wiley hit F5 in his browser. Still nothing changed.
Over the course of the hour that followed, Wiley grew increasingly more bewildered and panicked as he tried in vain to get the new TNT barrel to show up on the article page. He uploaded the image several more times, closed and re-opened his browser, deleted
and then reloaded the image, re-published and re-approved the actual article page, and even got the administrators to flush the SharePoint BLOB Cache. None of the actions made a difference.
The Coyote Never Wins
Why didn’t any of Wiley’s efforts make a difference? Because what Wiley didn’t understand was that there was nothing he could do short of flushing his cache that would prompt the browser to re-request the updated image. The browser started using the cached
copy of the image after the first request Wiley made in the morning; i.e., the request to verify that the image on the page was incorrect as Fulfillment indicated. For another 24 hours (86400 seconds), the browser would continue to use the cached image.
Wiley’s image problem was just one of the potential issues that might surface as a result of the BLOB Cache change. It was also one of the more visible problems. In looking at the
path attribute of the BlobCache element, you might have noticed some of the other file types that got cached by default – file types with
js (JavaScript) and css (Cascading Style Sheets) extensions, for example. Any of those file types which were served from site collection lists and libraries would also be impacted by the “fetch once and use for 24 hours” behavior.
If this helped you resolve your issue, please mark it Answered -
XSL variable-of document name from document library list does not render
I'm currently building a custom XSL file that is to be linked to a webpart so I can create a custom view. I must say I am new to XSL coding though I have background in html, javascript, php.
I'm able to render general columns that has been added (from document properties) in the document library I'm pulling data from but cannot seem to figure out how to render out the title. It is a document library so it is to be pulling the name of the document
added to the library.
In the aspx, I did try changing all name types (ones with links, without, with edit etc.) but no luck.
Here is my xsl code so far:
<xsl:template name="block.rowview">
<style>
.sktile{
width:200px; height:200px; border:#000 solid thin;
float:left; margin:5px; overflow:hidden
</style>
<div class="sktile">
<xsl:value-of select="@LinkFilename" />
<xsl:value-of select="@Description0" disable-output-escaping="yes"/>
<xsl:value-of select="@Recording_x0020_Date" />
<xsl:value-of select="@Presenter" disable-output-escaping="yes"/>
<xsl:value-of select="@Tools" disable-output-escaping="yes"/>
</div>
</xsl:template>
And here are the field references:
<FieldRef Name="LinkFilename"/>
<FieldRef Name="Recording_x0020_Date"/>
<FieldRef Name="Presenter"/>
<FieldRef Name="Tools"/>
<FieldRef Name="Description0"/>
So the field I'm struggling to show is the "LinkFilename" It would be great if someone can point out what I'm missing or what I'm doing wrong. Thanks in advance!Hi, Paul
Here are two VIs. Local1 return an error while building and local2 works fine.
Please let me know what's wrong!
In previous messege I've asked for a list of bugs in 8.20 and 8.0.1, do you know if it is available?
Thank you,
Andrej
Attachments:
local1.vi 11 KB
local2.vi 12 KB -
I currently am using PPT to expose data from a Microsoft Analysis Server cube. The cube is wide open and requires no permissions to access.
The behavior of my filters is odd as sometimes they work perfectly fine, and other times I receive the following error upon report run:
Unable to get filter values.
An unexpected error occurred. Error 10828. Additional details have been logged for your administrator.
I have looked at the ULS logs and found the following:
An unexpected error occurred. Error 10828. Exception details: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.PerformancePoint.Scorecards.Server.PmServer.QueryTimeIntelligenceInternal(DataSource dataSource, DateTime currentTime, String formula)
at Microsoft.PerformancePoint.Scorecards.Server.PmServer.QueryTimeIntelligence(RepositoryLocation dataSourceLocation, DateTime currentTime, String formula)
An exception occurred while rendering a Web control. The following diagnostic information might help to determine the cause of this problem: Microsoft.PerformancePoint.Scorecards.BpmException: Unable to get filter values. PerformancePoint Services
error code 20700.
This is odd to me, as I can trick the report to run by changing the date filters to another day, then back to the original days that error'ed out and everything is fine. Some guidance would be appreciated.Hi,
Do you mean that you have Office 2007 and Office 2010 both installed in you computer?
Based on my test, I copy a Access 2010 database into a computer only installed Offic 2007, then using Excel 2007 to import Access database data, no error occurred.
So double click the Access database to see whether the databased is opened with Access 2007 or Access 2010. If it is opened with Access 2010, then try to save it as Access 2007 to
check the issue.
Jaynet Zhang
TechNet Community Support -
Getting file name from a file path
Hello
I have got a String called filePath and it holds: "C:\Documents and Settings\paul\MyDocuments\nihtd.txt".
What I want do is to have another String variable called fileName that will use the 'filePath' variable to return the name on the file (that been "nihtd.txt" for the example given) but it must work with any file path for any file type.
Can anyone help? I have tried various ways but with no success.
Many thanks
PaulHmm, I just ran across another distinction between doing this by creating a File object as opposed to doing this by analysing the String: performance.
I always thought that creation of file objects is relatively cheap, since the Filesystem is not actually accessed when you create a new File instance. Apparently that is not true, at least not if you are on Windows and the file is on another server. Something like new File(\\server\share\file.txt) will create network traffic on Windows. So if you only meant to use the File class for parsing text, you might want to think again.
I would be interested to know how the FileSystem class is implemented on different platforms. Do you know where I can read up on that?
Cheers, HJK -
hi ,
there is a path "c:\abc\abc\abc\abc\abc.doc", i have to get file name from it.
but i had to write a dynamic code which can get the file name from any given path.Smoke me a kipper, I'll be back before breakfast.
SQL> var extended_filepath varchar2(128)
SQL> exec :extended_filepath := '/this/is/a/path/to/a/file.txt'
PL/SQL procedure successfully completed.
SQL> select instr(:extended_filepath, '/', -1)
2 from dual
3 /
INSTR(:EXTENDED_FILEPATH,'/',-1)
21
SQL> select substr(:extended_filepath, instr(:extended_filepath, '/', -1) +1)
2 from dual
3 /
SUBSTR(:EXTENDED_FILEPATH,INSTR(:EXTENDED_FILEPATH,'/',-1)+1)
file.txt
SQL> Cheers, APC -
How to get the target file name from an URL?
Hi there,
I am trying to download data from an URL and save the content in a file that have the same name as the file on the server. In some way, what I want to do is pretty similar to what you can do when you do a right click on a link in Internet Explorer (or any other web browser) and choose "save target as".
If the URL is a direct link to the file (for example: http://java.sun.com/images/e8_java_logo_red.jpg ), I do not have any problem:
URL url = new URL("http://java.sun.com/images/e8_java_logo_red.jpg");
System.out.println("Opening connection to " + url + "...");
// Copy resource to local file
InputStream is = url.openStream();
FileOutputStream fos=null;
String fileName = null;
StringTokenizer st=new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
fileName=st.nextToken();
System.out.println("The file name will be: " + fileName);
File localFile= new File(System.getProperty("user.dir"), fileName);
fos = new FileOutputStream(localFile);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = is.read(buf)) != -1) {
fos.write(buf, 0, i);
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (is != null)
is.close();
if (fos != null)
fos.close();
}Everything is fine, the file name I get is "e8_java_logo_red.jpg", which is what I expect to get.
However, if the URL is an indirect link to the file (for example: http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719 , which link to a file named JavaSetup6u18-rv.exe ), the similar code return AutoDL?BundleId=37719 as file name, when I would like to have JavaSetup6u18-rv.exe .
URL url = new URL("http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719");
System.out.println("Opening connection to " + url + "...");
// Copy resource to local file
InputStream is = url.openStream();
FileOutputStream fos=null;
String fileName = null;
StringTokenizer st=new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
fileName=st.nextToken();
System.out.println("The file name will be: " + fileName);
File localFile= new File(System.getProperty("user.dir"), fileName);
fos = new FileOutputStream(localFile);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = is.read(buf)) != -1) {
fos.write(buf, 0, i);
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (is != null)
is.close();
if (fos != null)
fos.close();
}Do you know how I can do that.
Thanks for your help
// JB
Edited by: jb-from-sydney on Feb 9, 2010 10:37 PMThanks for your answer.
By following your idea, I found out that one of the header ( content-disposition ) can contain the name to be used if the file is downloaded. Here is the full code that allow you to download locally a file on the Internet:
* Download locally a file from a given URL.
* @param url - the url.
* @param destinationFolder - The destination folder.
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
public static final File downloadFile(URL url, File destinationFolder) throws IOException {
URLConnection urlC = url.openConnection();
InputStream is = urlC.getInputStream();
FileOutputStream fos = null;
String fileName = getFileName(urlC);
destinationFolder.mkdirs();
File localFile = new File(destinationFolder, fileName);
fos = new FileOutputStream(localFile);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = is.read(buf)) != -1) {
fos.write(buf, 0, i);
} finally {
if (is != null)
is.close();
if (fos != null)
fos.close();
return localFile;
* Returns the file name associated to an url connection.<br />
* The result is not a path but just a file name.
* @param urlC - the url connection
* @return the file name
* @throws IOException Signals that an I/O exception has occurred.
private static final String getFileName(URLConnection urlC) throws IOException {
String fileName = null;
String contentDisposition = urlC.getHeaderField("content-disposition");
if (contentDisposition != null) {
fileName = extractFileNameFromContentDisposition(contentDisposition);
// if the file name cannot be extracted from the content-disposition
// header, using the url.getFilename() method
if (fileName == null) {
StringTokenizer st = new StringTokenizer(urlC.getURL().getFile(), "/");
while (st.hasMoreTokens())
fileName = st.nextToken();
return fileName;
* Extract the file name from the content disposition header.
* <p>
* See <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html">http:
* //www.w3.org/Protocols/rfc2616/rfc2616-sec19.html</a> for detailled
* information regarding the headers in HTML.
* @param contentDisposition - the content-disposition header. Cannot be
* <code>null>/code>.
* @return the file name, or <code>null</code> if the content-disposition
* header does not contain the filename attribute.
private static final String extractFileNameFromContentDisposition(
String contentDisposition) {
String[] attributes = contentDisposition.split(";");
for (String a : attributes) {
if (a.toLowerCase().contains("filename")) {
// The attribute is the file name. The filename is between
// quotes.
return a.substring(a.indexOf('\"') + 1, a.lastIndexOf('\"'));
// not found
return null;
} -
How to get the file name from Oracle B2B 10g
Hi My requirement is I am getting a CSV file from Trading partner, I am using oracle 10g b2b to translate the data.
In my BPEL 10g I am using AQ adapter to get the message from IP_IN_QUEUE.
Now I want to get the file name Eg: SampleFile.dat of the CSV file in my BPEL process.
I tried using the b2b.filename property in the receive activity and it is not getting the file name.
<sequence name="main">
<receive name="Receive_Note" partnerLink="GetB2BNote"
portType="ns1:Dequeue_ptt" operation="Dequeue"
variable="Receive_Note_Dequeue_InputVariable"
createInstance="yes">
<bpelx:property name="b2b.fileName" variable="WriteFileName"/>
</receive>
</sequence>
Can you help me to get the file name from Oracle b2b 10g ?
Thanks,
b2b userHi My requirement is I am getting a CSV file from Trading partner, I am using oracle 10g b2b to translate the data.
In my BPEL 10g I am using AQ adapter to get the message from IP_IN_QUEUE.
Now I want to get the file name Eg: SampleFile.dat of the CSV file in my BPEL process.
I tried using the b2b.filename property in the receive activity and it is not getting the file name.
<sequence name="main">
<receive name="Receive_Note" partnerLink="GetB2BNote"
portType="ns1:Dequeue_ptt" operation="Dequeue"
variable="Receive_Note_Dequeue_InputVariable"
createInstance="yes">
<bpelx:property name="b2b.fileName" variable="WriteFileName"/>
</receive>
</sequence>
Can you help me to get the file name from Oracle b2b 10g ?
Thanks,
b2b user
Maybe you are looking for
-
I am trying to set up SQL generator to generate report on my oracle portlet. before doing so i need to download a zip file.i follow the steps that provided inside the file.(mannual deployment) its fine for the first 3 steps. step 4 is about running o
-
Selected playlist for syncing is deleted??
when i conect my ipod da mesage comes out saying "songz on the ipod 'smunkii's ipod' cannot be updated because all of the playlists selected for syncing no longer exists" how do i create syncing playlists? hellp meee
-
Is there a setting or an app for the iPhone 4 that allows you to see that you have new mail messages from the "lock screen" like SMS and missed call messages? My primary e-mail account is MS Exchange and I'm running iOS 5. Thanks!
-
Is Text/Integer Field required in Flat Lookup table?
Hi, I have a flat look up table. In that i want to create 4 Flat lookup fields....... one of them will be a display field. But when i Verify Repository with this structure then it gives me Fatal Error: $$$ Fatal error(1323): Table 'Product Hierarchy'
-
Hi, I've just got a question concerning the best way to save my data. I'm using LV 7.0 and Vision 7.1 on a 2P Microscope. I'm acquiring images, heartbeat of the animal and a stimulation signal which all depend on the same internal clock. Now, for eac