.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan
Fauzul Azmi
Asad Ali
Post New Web Links

Getting relative filename from directory & file

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :.NET Framework
 

Hi all;

Is there a method where if I have a directory and a fully qualified filename, I can get a relative filename from the driectory to the file?

And is there a way to do the same thing with an http driectory and filename?

thanks - dave


The future of B.I. - Raw & Uncut


View Complete Post


More Related Resource Links

Get .doc or .docx file from Directory

  

Hi,

I want to get files(.doc,.docx) from Directory and show the Content with formatting in a webform.
Is there any solution?
Please help me.

Thanks in advance.


filename without directory

  
how to insert the exact  filename to the database without getting the full directory like c://something/something/filename  into the column 'Filename'     waitng for reply

Directory lookup for the file failed with the operating system error 5

  
Hi I have a Windows desktop application that uses a SQLServer Express database.  The database files are downloaded from my website, followed by the application download (written in VBE).  The first procedure is to attach the database to the SQLServer instance from within the application. I have two test machines one runs Windows XP x84, the other Windows 7 x64.  I never have issues on attaching the database files in my test envirnoment but twice now other people downloading have got the following error System.Data.Sqlclient.sqlexception (ox 80131904) Directory lookup for the file C:\Documtents and Settings\Administrator\Desktop\Tem1.mdf failed with the operating system error 5 (failed to retrieve text for this error. Reason 1815) changed database context to 'master'. I'm not sure what the problem is and therefore how to correct the issue.  I attach the database in code using the create statement e.g. cmd7.CommandText = "USE Master CREATE DATABASE Tem1 ON PRIMARY (FILENAME = '" & DBFullPath & "') LOG ON (FILENAME = '" & DbLogPath & "') FOR ATTACH" Any help or suggestions would be very much appreciated. Chris    

how can i replace a file from a directory using file upload control and c# in a web applicatin

  
i m developing a web based appllication with asp.net and c#. I want to replace a file that is in a directory by code.

Creating Database gives error : "Directory lookup for the file "xxxxx.mdf" failed with the operating

  
Hello FriendsI am creating Database using SQLDMOcode is as follows... Code Snippet SQLServer2Class server = new SQLServer2Class();server.EnableBcp = true;server.Connect(WebConfigurationManager.AppSettings["ServerName"] ,WebConfigurationManager.AppSettings["UserName"],WebConfigurationManager.AppSettings["Password"]);DBFileClass dbFile = new DBFileClass();           dbFile.Name = dbName;          dbFile.PhysicalName = "C:\\" + dbName + ".mdf";          dbFile.Size = 300;          dbFile.FileGrowthType = SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB;          dbFile.FileGrowth = 25;          dbFile.PrimaryFile = true;          LogFile2Class dbLogFile = new LogFile2Class();          dbLogFile.Name = dbName + "_log";          dbLogFile.PhysicalName = "C:\\" + dbName + "_log.ldf";          dbLogFile.FileGrowthType = SQLDMO_GROWTH_TYPE.SQLDMOGrowth_Percent;          dbLogFile.FileGrowth = 10;          Database2Class newDb = new Database2Class();          newDb.Name = dbName;          newDb.FileGroups.Item("PRIMARY").DBFiles.Add((DBFile)dbFile);          newDb.TransactionLog.LogFiles.Add((_LogFile)dbLogFile);          server.Databases.Add((_Database)newDb); This Code Generates Following Error !!]Microsoft][ODBC SQL Server Driver][SQL Server]Directory lookup for the file "D:\Projects\my_system\mySys

How to show a message box on an invalid filename entered while saving a file using save file dialog

  
Hi all i have written a code to display a message box if invalid characters are entered while saving the file but my message box is not displaying. Actually i will have a save file dialog option to save a file if the filename starts or consists of the following    \\/:*?<>|"  I would like to display a message box as invalid or illegalcharacters in file My code is as follows    Stream myStream;                          SaveFileDialog saveFileDialog1 = new SaveFileDialog();                            saveFileDialog1.InitialDirectory = @"C:\";                          saveFileDialog1.DefaultExt = "txt";                          saveFileDialog1.Filter = "(*.txt)|*.txt";                          saveFileDialog1.FilterIndex = 2;                          saveFileDialog1.RestoreDirectory = true;                            if (saveFileDialog1.ShowDialog() == DialogR

FAQ: How do I listen to changes in a file/directory in the windows file system?

  
How do I listen to changes in a file/directory in the windows file system?Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

A GUID might be prepended to the filename of the log file

  

Hi,

Problem Definition:

I have an asp.net application when i am using microsft enterprise library for logging v4.1.

I found that a guid is added to the name of my file. I did googling and came to know that because of the following reasons it  is happening:

A RollingFileTraceListener instance "owns" the log file it is writing to and locks it for exclusive write access when it writes the first log entry. It keeps the file locked until the instance is disposed. If another RollingFileTraceListener  instance is created that points to the same file, before the first instance is disposed, the second instance cannot open this file for writing and will write to a new file with a GUID prepended to its name.

So my question is how i can overcome this issue?

Please do reply. Thanks in advance.



Logging Application Block -- A GUID might be prepended to the filename of the log file

  

Hi,

Here is my problem definintion.

I am using Microsoft.Practices.EnterpriseLibrary.Logging.dll 4.1 version. It is found that

"A GUID might be prepended to the filename of the log file".

I did some googling and came to know that this is known issue from the following link

http://bloggingabout.net/blogs/erwyn/pages/rolling-file-trace-listener.aspx

So how to resolve this. Is there any cleaner approch that i can use.

Please do reply.

Thanks in advance.


Directory.Move leads to corrupted 'file'

  

Hello All,

 

I have earlier used Directory.Move to move one folder into an existing sub folder. The path I specified happened to have a slightly different case to the existing directory (temp vs Temp), and the result is two folders, one called temp the other Temp. Normally we can't do this through windows as it recognises the two folders to ultimately have the same name regardless of case. I expected the .NET class to handle in the same way.


I've deleted the original Temp folder, but this 'temp' directory still remains... it's recognised by Windows as a directory yet also reported as not existing! Whilst I could probably live with a redundant corrupt file somewhere on my disk it's really causing some problems with recursive functions that, like the rest of windows, get confused by the directory which exists but doesn't exist.

Has anybody had this same problem? Or rather, how can I fix this?

 

Running VS2008 on Win7.

 

Regards,

Chris


The file or directory is corrupted or unreadable

  

Hi,

I have installed a two node active/passive sql 2005 cluster on windows 2003 in vmware workstation environment . the cluster installed successfully (configured the cluster according to the link "http://www.bradspace.net/blog/kb/?p=91&more=1&c=1&tb=1&pb=1"). but when I try to move sql server resource group to passive node, it gets fail by logging following error message in event log "initerrlog: Could not open error log file 'G:\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG'. Operating system error = 1392(The file or directory is corrupted and unreadable.)."

I have taken sql resources group offline and manually moved only sql server shared drive to other node and i have found that i am not being able to access error log or any other folder including data on node 2. the operating system shows a error saying that disk is corrupted. I have run chkdsk which delete's all the files of sql setup.

I re-installed sql server, but again found the same problem . by wo

The file or directory is corrupted or unreadable

  

Hi,

I have installed a two node active/passive sql 2005 cluster on windows 2003 in vmware workstation environment . the cluster installed successfully (configured the cluster according to the link "http://www.bradspace.net/blog/kb/?p=91&more=1&c=1&tb=1&pb=1"). but when I try to move sql server resource group to passive node, it gets fail by logging following error message in event log "initerrlog: Could not open error log file 'G:\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG'. Operating system error = 1392(The file or directory is corrupted and unreadable.)."

I have taken sql resources group offline and manually moved only sql server shared drive to other node and i have found that i am not being able to access error log or any other folder including data on node 2. the operating system shows a error saying that disk is corrupted. I have run chkdsk which delete's all the files of sql setup.

I re-installed sql server, but again found the same problem . by wo

Writing File in Oracle to Secured Directory on NAS Server

  

I have a stored procedure that creates a comma delimited file. I can easily write to a directory on the database server, but I would like to write the file to a mapped network directory on a NAS server. The issue, at least conceptually (sorry for being a novice here), is that I have no way of accessing or embedding the necessary username/password to write to the specified directory.

Based on initial research, it looks like the oracle account is the one writing the file. Would that mean that the oracle account would have to have the appropriate privileges to the NAS directory? Who would that oracle user be? The niku account user being used to execute the proc?

Kind of lost here. Would like to send directly to the NAS to avoid an SFTP to another environment.



Why visual studio does not generate .vb file when, publishing project into normal directory other th

  

Hello,

I am using visual studio 2005,

When I publish my asp.net project into C:\Documents and Settings\temp\example, then it publish successfully,but into  C:\Documents and Settings\temp\example location , I dont see default.aspx.vb file. I do see Bin directory, PrecompiledApp.config file, webconfig file.

I am not sure , why it does not generate default.aspx.vb file (may be instead it is created PrecompiledApp.config file)

or is this because I am not publishing file into virtual directory.

Give me some advice on this.

Thank you

maxmax


I want SSIS to fire everytime a file is placed in a directory

  

I am slightly confused by this. I have setup a WMI file watcher on a directory which is designed to fire a data flow task and then delete said file each time I place a file in the directory.

 

However, when I run it in debug everything is fine, for the first run (the file is processed and then deleted). HEre is my problem, the WMI task, and my other task return with Success after processing the file meaning when I place another file in the directory (after the event) nothing happens?

Could someone explain what I am missing? I am quite confused.


File.Copy to Program Files Directory.

  
I searched high and low and have found some discussions on this topic but do seem to see any solutions.   So here is my issue.   I have an application that will copy 2 files to the Program Files directory.   What happen is, when I run it and the files exist (this should be what normally happens) I get accessed denied.   If I try to do a File.Delete (in code) first I get an access denied, however I can manually (in OS windows explorer) delete the files and then the copy will work.   I am running the application as Admin, so permissions to the folder are good.  

The application is restoring a 3rd party software file that tends to get corrupted a lot.   We have mechanism that will back this file up, but when I try to restore it I get the problem described above.   (not a file lock issue, I have made sure no programs have a handle to the file)

OS = Vista32
Program written in C#

Is there anyway of accomplishing this?

Thanks

Cannot move file from one ftp directory to another in .NET Framework 4.0

  

I'm in the progress of updating my C++ code from visual studio 2005 to visual studio 2010.  I've come across a problem where the FtpWebRequest class is unable to move a file from one directory to another directory on a ftp server when an absolute FtpWebRequest::RenameTo path is specified.

For example, I want to move the file, file.txt from source to destination as follows:
source: /working/
destination: /data/

An example of the code I use to handle this is below:

    Uri^ target = gcnew Uri( gcnew String("FTP://servername//working/file.txt"));
   
    FtpWebRequest^ request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( target ));
   
    request->Credentials = gcnew NetworkCredential( gcnew String("username"), gcnew String("password") );


    request->EnableSsl = (ftpType == ftpTypeFTPS) ? true : false;
    request->KeepAlive = false;
    request->Method = WebRequestMethods::Ftp::Rename;
    request->RenameTo = gcnew String("/data/file.txt");
    request->GetResponse()->Close();


The problem is that FtpWebRequest treats the FtpWeb

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend